tourless
Board Regular
- Joined
- Feb 8, 2007
- Messages
- 144
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have the following code that I'm expecting to break out of the loop once it no longer sees a match on the customer name. But what I'm noticing is the loop continues until it exhausts all rows in the range. I've tried a few variations with no luck so far... How can I get that to work properly?
For k = 1 To LastRow(wsItemInfo)
Do While wsItemInfo.Cells(k, 1).Value = customerRow.Value
wsItemInfo.Cells(k, 2).Copy
wsCustomerReportCard.Range("A" & LastRow(wsCustomerReportCard) + 1).PasteSpecial xlPasteValues
wsItemInfo.Cells(k, 3).Copy
wsCustomerReportCard.Range("B" & LastRow(wsCustomerReportCard, "B") + 1).PasteSpecial xlPasteValues
wsItemInfo.Cells(k, 4).Copy
wsCustomerReportCard.Range("E" & LastRow(wsCustomerReportCard, "E") + 1).PasteSpecial xlPasteValues
k = k + 1
Loop
Next k
I have the following code that I'm expecting to break out of the loop once it no longer sees a match on the customer name. But what I'm noticing is the loop continues until it exhausts all rows in the range. I've tried a few variations with no luck so far... How can I get that to work properly?
For k = 1 To LastRow(wsItemInfo)
Do While wsItemInfo.Cells(k, 1).Value = customerRow.Value
wsItemInfo.Cells(k, 2).Copy
wsCustomerReportCard.Range("A" & LastRow(wsCustomerReportCard) + 1).PasteSpecial xlPasteValues
wsItemInfo.Cells(k, 3).Copy
wsCustomerReportCard.Range("B" & LastRow(wsCustomerReportCard, "B") + 1).PasteSpecial xlPasteValues
wsItemInfo.Cells(k, 4).Copy
wsCustomerReportCard.Range("E" & LastRow(wsCustomerReportCard, "E") + 1).PasteSpecial xlPasteValues
k = k + 1
Loop
Next k