0
あるブックから別のブックにデータをコピーしたいと思います。1つのブックからデータを抽出し、コメントを付けて別のブックに貼り付ける
ソースブックには、各行にいくつかのコメントが記載されています。コピーするために自分のコードを使用すると、それに応じてコメントがコピーされません。いずれかの助け、どのようにコメント欄で1つのブックから別のブックにコピーすることができますか?私のコメントは、私はあなたのコードは未修飾の参照を修正し、イミディエイトウィンドウに送信元と送信先の範囲のアドレスを印刷リファクタリングP.
Sub Extract()
Dim DestinationWB As Workbook
Dim OriginWB As Workbook
Dim path1 As String
Dim FileWithPath As String
Dim lastRow As Long, i As Long, LastCol As Long
Dim TheHeader As String
Dim cell As Range
Set DestinationWB = ThisWorkbook
path1 = DestinationWB.Path
FileWithPath = path1 & "\Downloads\CTT.xlsx"
Set OriginWB = Workbooks.Open(filename:=FileWithPath)
lastRow = OriginWB.Worksheets("Report").Cells(Rows.count, 1).End(xlUp).Row
LastCol = OriginWB.Worksheets("Report").Cells(22, Columns.count).End(xlToLeft).Column
For i = 1 To LastCol
'get the name of the field (names are in row 22)
TheHeader = OriginWB.Worksheets("Report").Cells(22, i).Value
With DestinationWB.Worksheets("CTT").Range("A4:P4")
'Find the name of the field (TheHeader) in the destination (in row 4)
Set cell = .Find(TheHeader, LookIn:=xlValues)
End With
If Not cell Is Nothing Then
OriginWB.Worksheets("Report").Range(Cells(23, i), Cells(lastRow, i)).Copy Destination:=DestinationWB.Worksheets("CTT").Cells(5, cell.Column)
Else
'handle the error
End If
Next i
OriginWB.Close SaveChanges:=False
End Sub
あなたはいない "は、それに応じて" とはどういう意味ですか?私はあなたのコードの中で、コメントの参照を見ることができません - あなたはセルの内容を意味しますか? – SJR
@SJR ya。私は、セルの内容# – Mikz