VBA のヘルプが必要です。
10 個のワークシートを含むワークブックがあります。最初の 8 をループして、特定の値を 10 番目の値にコピーしたいと思います。
これが私がこれまでに持っているものです:
Sub GetData()
Dim wbSource As Workbook
Dim wsTarget As Worksheet
Dim lastline As Integer
Set wbSource = ThisWorkbook 'everything will be from this workbook
Set wsTarget = wbSource.Sheets(10) 'wsTarget is my summary sheet, which is the the 10th tab
For x = 1 To 6
wsTarget.Range("H" & x).Value = wbSource.Sheets(1).Range("S" & x) 'copying over some info from the first sheet onto summary sheet, since this info will be the same on all sheets
Next x
For k = 1 To 8 ' sheet 10 is my summary sheet
Dim j As Integer 'this is a pointer that moves within each wsSource to look for values to be copied
Dim m As Integer 'this is the pointer that moves within the summary (wsTarget) sheets to paste values
j = 8 ' j amd m happen to be the same, coincidence
m = 8
For i = 1 To wbSource.Sheets(k).Range("X65536").End(xlUp).Row 'for each line in worksheet (k)
MatchCase = False 'do not match case
If wbSource.Sheets(k).Range("X" & j) = "y" Then ' if "Y/y" is found
lastline = wbSource.Sheets(k).Range("X65536").End(xlUp).Row
For a = 1 To lastline 'search until the spreadsheet is empty
If IsEmpty(wsTarget.Range("B" & m).Value) Then ' if this cell is empty, copy over the values from the wbSource, and here are the values to copy:
wsTarget.Range("B" & m).Value = wbSource.Sheets(k).Range("D" & j).Value 'exiting or new
wsTarget.Range("C" & m).Value = wbSource.Sheets(k).Range("I" & j).Value 'number
wsTarget.Range("D" & m).Value = wbSource.Sheets(k).Range("K" & j).Value 'title
wsTarget.Range("E" & m).Value = wbSource.Sheets(k).Range("P" & j).Value 'revision
wsTarget.Range("F" & m).Value = wbSource.Sheets(k).Range("Q" & j).Value 'status
wsTarget.Range("G" & m).Value = wbSource.Sheets(k).Range("R" & j).Value 'part of DOC number
wsTarget.Range("H" & m).Value = wbSource.Sheets(k).Range("U" & j).Value 'remarks
wsTarget.Range("I" & m).Value = wbSource.Sheets(k).Range("X" & j).Value 'confirmation
ElseIf Not IsEmpty(wsTarget.Range("B" & m).Value) Then 'if this cell already contains a value, move to next line
m = m + 1
End If
m = m + 1 'after a value has been pasted, move the next line
j = j + 1 'move to next line in wbSource worksheets
Next a ' next line in wbSource
Next i ' next line in wsTarget
Next k 'next workbook
End Sub
今、コードを実行しようとすると、「コンパイル エラー: for なしの次へ」というエラー メッセージが表示され、次の i が強調表示されます。私は何を間違っていますか?助けてください!
私のコードをより効率的にする方法について何か提案があれば、私に知らせてください。私は提案を受け入れます。
前もって感謝します