Hi..
Used autofilter instead.. it should do what you want.. although it took about 30 seconds to run on my machine..
Both Workbooks need to be open..
Private Sub CommandButton1_Click()
Dim LastRow As Long, LastRow2 As Long, lr As Long, i As Long
Dim Crit1 As String, v As Range
Application.ScreenUpdating = False
With ThisWorkbook
LastRow = Sheets("Import to StoreProduct").Range("A" & Rows.Count).End(xlUp).Row
LastRow2 = Workbooks("AllocatedList.xlsx").Sheets("Data").Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
Crit1 = Sheets("Import to StoreProduct").Cells(i, 1).Value
Sheets("Import to StoreProduct").Range("A1:G" & LastRow).AutoFilter Field:=1, Criteria1:=Crit1
Workbooks("AllocatedList.xlsx").Sheets("Data").Range("A1:I" & LastRow2).AutoFilter Field:=3, Criteria1:=Crit1
lr = Sheets("Import to StoreProduct").Range("A" & Rows.Count).End(xlUp).SpecialCells(12).Row
Set v = Range("A1:A" & Range("A65536").End(xlUp).Row).Offset(1).SpecialCells(xlCellTypeVisible)
If Workbooks("AllocatedList.xlsx").Sheets("Data").Range("I1:I" & LastRow2).SpecialCells(xlCellTypeVisible).Count > 1 Then
Workbooks("AllocatedList.xlsx").Sheets("Data").Range("I2:I" & LastRow2).SpecialCells(xlCellTypeVisible).Copy _
Destination:=Sheets("Import to StoreProduct").Range("D" & v.Row)
End If
Next i
If Sheets("Import to StoreProduct").AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Workbooks("AllocatedList.xlsx").Activate
If Workbooks("AllocatedList.xlsx").Sheets("Data").AutoFilterMode Then ActiveSheet.AutoFilterMode = False
.Activate
End With
Application.ScreenUpdating = True
End Sub
Bookmarks