VBA to loop through code

Barry NP

New Member
Joined
Jul 18, 2017
Messages
24
Hi all,

I need to add code to loop through the code below, but I'm not exactly sure how to do this. Any help would be greatly appreciated.

What this is currently doing (In excel) is filtering on column "H" to find the criteria "No Match". Once found a new row is added to my table in within columns A to E. Then Un-filter column "H". Then repeat filter on column "H" to find the next "No Match" criteria and insert a new row in the table. The filtering and un-filtering needs to be done each time in order to recalculate the formulas in column H below the new added table row.
Can this code be looped until there are no more occurrences of "No Match" in column "H".

The recorded code below does this procedure 3 times but I would like to loop the code until there are no more occurrences of "No Match" in column "H".


Sub Insert_Rows()
'
' Insert_Rows Macro
'

'
ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1, Criteria1:= _
"No Match"
Range("A329:E329").Select
Selection.ListObject.ListRows.Add (328)
ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1

ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1, Criteria1:= _
"No Match"
Range("A331:E331").Select
Selection.ListObject.ListRows.Add (330)
ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1

ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1, Criteria1:= _
"No Match"
Range("A339:E339").Select
Selection.ListObject.ListRows.Add (338)
ActiveSheet.Range("$H$1:$H$3324").AutoFilter Field:=1

End Sub


Many thanks in advance.

Barry.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Barry

How do you know where to add the new row?
 
Upvote 0
Barry

How do you know where to add the new row?

Hi Norie,

Thanks for your response. The new row will be inserted in the table where the filtered match in column H - "No Match" occurs. So if the first "No Match" is on row 100, then new row will be inserted in row 100 and so on until there are no more "No Match" in column H.
Hope that helps
Barry
 
Upvote 0
Barry

Do you need to filter?

Could it not be done by finding the first occurrence of 'No Match', inserting a row, finding the next occurrence of 'No Match', inserting a row...?
 
Upvote 0
Hi Norrie, apols for the delay, been off work a few days! Thanks for your last message. To be honest this is how its currently done by filtering and inserting new rows. This has been working fine, however, the data is now expanding, which means that manually filtering and inserting rows for each occurrence of "No Match" is taking much longer. Was hoping that VBA could be of use to speed up the process.
 
Upvote 0
Barry

I wasn't suggesting to change to do it manually, what I described doing could also be done in VBA.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top