2016-11-16 14 views

答えて

1

は、このいずれかを試しています

Public Sub CopyRows() 

    Dim ewbT As Workbook: Set ewbT = ThisWorkbook ' Change ewbT to target Workbook, maybe ActiveWorkbook 
    Dim ewsA As Worksheet: Set ewsA = ewbT.Worksheets("A") 
    Dim ewsB As Worksheet: Set ewsB = ewbT.Worksheets("B") 
    Dim ewsC As Worksheet: Set ewsC = ewbT.Worksheets("C") 
    Dim ewsD As Worksheet: Set ewsD = ewbT.Worksheets("D") 

    Dim dctPolicy As Dictionary: Set dctPolicy = New Dictionary 
    Dim r As Long: For r = 2 To ewsA.UsedRange.Rows.Count ' Change 2 to first row of data 
     dctPolicy.Add ewsA.Cells(r, 1).Value, 0 
    Next r 

    For r = 2 To ewsB.UsedRange.Rows.Count ' Change 2 to first row of data 
     Dim varTemp() As Variant: ReDim varTemp(0 To 0, 0 To 3) 
     varTemp = ewsB.Cells(r, 1).Resize(1, 4).Value 
     Dim ewsT As Worksheet: Set ewsT = ewsC 
     If dctPolicy.Exists(ewsB.Cells(r, 1).Value) = False Then 
      Set ewsT = ewsD 
     End If 
     ewsT.Cells(ewsC.UsedRange.Rows.Count + 1, 1).Resize(1, 4).Value = varTemp 
    Next r 

End Sub 

また、ツール>参照情報> Microsoft Scripting Runtimeが有効になっている必要がありますのでご注意ください。

+0

ありがとうございました。 – ChrisM

関連する問題