|
▼迷える羊 さん:
Sub test3()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim r1 As Range, r2 As Range
Dim ws As Worksheet
Dim r3 As Range, r4 As Range
Dim c As Range, t As Range
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set r1 = ws1.Range("A13")
Set r2 = Union(ws2.Columns("H"), ws2.Columns("L"))
Set ws = Worksheets.Add
Set r3 = ws.Range("A1")
Set r4 = ws.Range("C1")
Range(r1, r1.End(xlDown)).Copy r3
r2.Copy r4
Set c = ws.Range("F1:F2")
c(2).Formula = "=countif(A:A,D2)>0"
Set t = ws.Range("H1")
r4.CurrentRegion.AdvancedFilter xlFilterCopy, c, t
Set t = t.CurrentRegion
With ws.Sort
.SortFields.Clear
.SortFields.Add2 _
Key:=t.Columns(2), _
CustomOrder:=WorksheetFunction.TextJoin(",", True, r3.CurrentRegion)
.SetRange t
.Header = xlYes
.Apply
End With
t.Columns(1).Copy r1.Offset(, 1)
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
Application.Goto r1, True
End Sub
|
|