|
▼K・Y さん:
こんばんは
>VBAの勉強のために課題を出されたのですが
>分からなくなったので質問させて頂きます
課題でしょうから、このような掲示板で回答をもらうというのは
「ズル」かもしれませんけど・・・
要件、わかりにくいのですが、
Sub Sample()
Dim sh As Worksheet
Dim v() As String
Dim i As Long
Dim k As Long
Dim s As String
Dim x As Long
Dim c As Range
Dim z As Long
Application.ScreenUpdating = False
Set sh = Workbooks("タスク.xls").Sheets("Sheet1")
sh.Cells.ClearContents
With Workbooks("課題.xls").Sheets("Sheet1")
With .UsedRange
z = .Cells(.Cells.Count).Row
End With
For Each c In .Range("A1:A" & z)
ReDim v(1 To 3)
x = c.Row
k = 0
For i = 1 To 3 'A列〜C列
s = c.Offset(, i - 1).Value
If Len(s) > 0 Then
k = k + 1
v(k) = s
End If
Next
If k > 0 Then
ReDim Preserve v(1 To k)
sh.Cells(x, "A").Value = "依" & Join(v, "-")
End If
sh.Cells(x, "C").Value = "依頼" & Format(Val(.Cells(x, "L")), "00000")
sh.Cells(x, "K").Value = .Cells(x, "Y").Value
Next
End With
sh.Parent.Activate
sh.Select
Set sh = Nothing
Application.ScreenUpdating = True
MsgBox "転記終了しました"
End Sub
|
|