そのため、いくつかの回答のある VBA の質問を調査しましたが、まだ行き詰っています。「By_Oppt_ID」、「Top_Bottom」、「Non_Top_Bottom」の 3 つのシートがあります。最初の 2 つには、それぞれ固有の名前を持つ大量の列があります。現在、「Top_Bottom」にない By_Oppt_ID の列がいくつかあります。したがって、By_Oppt_ID の各列名を「Top_Bottom」のすべての列名と比較し、列名が見つからない場合は、その列名とその下のすべての行を 3 番目のワークシート「Non_Top_Bottom」にコピーします。だからここに私が持っているものがあります:
Sub Copy_Rows_If()
Dim Range_1 As Worksheet, Range_2 As Worksheet
Dim c As Range
Set Range_1 = Workbooks("Complete_Last_Six_Months_Q_Results.xlsx").Sheets("Top_Bottom")
Set Range_2 = Workbooks("Complete_Last_Six_Months_Q_Results.xlsx").Sheets("By_Oppt_ID")
Application.ScreenUpdating = False ' Stays on the same screen even if referencing different worksheets
For Each c In Range_2.Range("A2:LX2")
' Checks for values not in Range_1
If Application.WorksheetFunction.CountIf(Range_1.Range("A1:CR1"), c.Value) = 0 Then
' If not, copies rows to new worksheet
' LR = .Cells(Row.Count, c).End(xUp).Row
c = ActiveCell
Sheets("By_Oppt_ID").Range("Activecell", "ActiveCell.End(xlDown)").Copy Destination:=Workbooks("Complete_Last_Six_Months_Q_Results.xlsx").Sheets("Non_Top_Bottom").Range("A1:A6745")
Set rgPaste = rgPaste.Offset(0, 1) 'Moves to the next col, but starts at the same row position
End If
Next c
End Sub
私はこのように多くの方法をコンパイルしましたが、一連のエラーが発生し続けています: Subscript Out of Range/ Method "Global_Range" Failure. 私は何を間違っていますか?