98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA loop or repeat tasks
VBA loop or repeat tasks
Resolved · Medium Priority · Version 2016
Quek has attended:
Excel VBA Advanced course
VBA loop or repeat tasks
Dear team,
How do i repeat this task until there is no more texts "N/A" in the column?
rrow = Sheets("Sheet 2").Range("A" & Rows.Count).End(xlUp).Row
For r = 1 To rrow
If Cells(r, "G").Text = "#N/A" Then
Sheets("Sheet 2").Rows(r).EntireRow.Delete
End If
Next
Somehow, when i run the macros once not all the rows get deleted?
And if i run it a few times then i get the data that i want.
Hope you can help.
Thanks.
RE: VBA loop or repeat tasks
Hi Shi Lin,
Thank you for the forum question.
If you start from the top you have the problem, because every time you delete a row all rows will move up and you will skip testing a row.
Try:
rrow = Sheets("Sheet 2").Range("A" & Rows.Count).End(xlUp).Row
For r = rrow To 1 step -1
If Cells(r, "G").Text = "#N/A" Then
Sheets("Sheet 2").Rows(r).EntireRow.Delete
End If
Next
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Tue 19 Mar 2019: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Generating Random NumbersTo generate a random number in Excel use the = RAND() function. |