あるワークブックから別のワークブックに指名された怒りを貼り付けようとしています。指名された範囲は SourceRange と呼ばれ、その宛先は TargetRange です。
ただし、TargetRange ワークブックの列 c2 にデータが存在する場合、SourceRange を TargetRange の次の Available 列に貼り付ける必要があります。
次のコードは現在、c2 にデータが存在しない場合は SourceRange を黄色でコピーし、データがある場合は緑にします。緑のインスタンスを c2 の次に使用可能な列に貼り付ける必要があるため、d2.
オフセット機能については知っていますが、どこで使用すればよいかわかりません。
Select Case MasterWorkbook.ActiveSheet.Range("c2") = ""
Case True
' The opened file automatically becomes the new active workbook and active worksheet.
Set SourceRange = ActiveSheet.Range("c2:c26")
Set TargetRange = MasterWorkbook.ActiveSheet.Range("c2:c29")
' Copy cell values one at a time from the source range to the target range.
For Row = 2 To 29
TargetRange.Cells(Row, 1).Value = SourceRange.Cells(Row, 1).Value
Next
ActiveWorkbook.Close
' Set background colour of target range.
TargetRange.Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Case False
' The opened file automatically becomes the new active workbook and active worksheet.
Set SourceRange = ActiveSheet.Range("c2:c26")
Set TargetRange = MasterWorkbook.ActiveSheet.Range("c2:c29")
' Copy cell values one at a time from the source range to the target range.
'Sheets.Add.Name = "workbookname"
For Row = 2 To 29
TargetRange.Cells(Row, 1).Value = SourceRange.Cells(Row, 1).Value
Next
ActiveWorkbook.Close
' Set background colour of target range.
TargetRange.Select
With Selection.Interior
.ColorIndex = 10
.Pattern = xlSolid
End With
End Select