Hi there! I am using this macro to sort through a master inventory list and transfer a row if the inputted "Vendor" is found when the InputBox populates. However, after the input, the InputBox keeps popping up and infinitely looping. How do I make it so that once a vendor name is entered, the code loops through the rows normally until the end of the master inventory list? Basically, I just want it to stop infinitely looping and to search for and copy the rows that contain the inputted vendor name. Thank you!
Sub For_RangeCopy2()
' Get the worksheets
Dim shRead As Worksheet
Set shRead = ThisWorkbook.Worksheets("Master")
Dim shWrite As Worksheet
Set shWrite = ThisWorkbook.Worksheets("PO Template")
' Get the range
Dim rg As Range
Set rg = shRead.Range("A1").CurrentRegion
With shWrite
End With
' Read through the data
Dim i As Long, row As Long
row = 1
For i = 1 To rg.Rows.Count
Dim vendor As String
vendor = InputBox("Type Vendor Name")
If rg.Cells(i, 3).Value2 = vendor Or i = 1 Then
' Copy using Range.Copy
rg.Rows(i).Copy
shWrite.Range("A" & row).PasteSpecial xlPasteValues
' move to the next output row
row = row + 1
End If
Next i
End Sub
Sub For_RangeCopy2()
' Get the worksheets
Dim shRead As Worksheet
Set shRead = ThisWorkbook.Worksheets("Master")
Dim shWrite As Worksheet
Set shWrite = ThisWorkbook.Worksheets("PO Template")
' Get the range
Dim rg As Range
Set rg = shRead.Range("A1").CurrentRegion
With shWrite
End With
' Read through the data
Dim i As Long, row As Long
row = 1
For i = 1 To rg.Rows.Count
Dim vendor As String
vendor = InputBox("Type Vendor Name")
If rg.Cells(i, 3).Value2 = vendor Or i = 1 Then
' Copy using Range.Copy
rg.Rows(i).Copy
shWrite.Range("A" & row).PasteSpecial xlPasteValues
' move to the next output row
row = row + 1
End If
Next i
End Sub
VBA Code: