This one should cover that.
Private Sub CommandButton1_Click()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim nextRow As Long, r As Long
Dim storeNo As String, Indicator As Boolean
Set ws1 = Sheets("Sheet1"): Set ws2 = Sheets("Data2")
Indicator = False
With ws1
.Cells(5, 4).CurrentRegion.Offset(1).ClearContents
storeNo = .Range("B4").Value
nextRow = .Range("D" & Rows.count).End(xlUp).Row + 1
End With
With ws2
For r = 2 To .Cells(.Rows.count, "A").End(xlUp).Row
If .Cells(r, 1) = storeNo Then
ws1.Cells(nextRow, 4).Resize(, 5) = Array(.Cells(r, 1), .Cells(r, 2), .Cells(r, 3), .Cells(r, 4), .Cells(r, 5))
nextRow = nextRow + 1: Indicator = True
End If
Next r
If Indicator = False Then MsgBox "No entries found for that No", vbInformation, ""
End With
End Sub
Bookmarks