Delete row if 1st cell not equal to defined value?

jmthompson

Well-known Member
Joined
Mar 31, 2008
Messages
966
New to VBA-
I have a template I use to reformat an exported report so it will import into another database. One of the things I need to do is divide this report into 26 separate reports.

What I would like to do is create a macro that will delete any rows where the first cell is not equal to a given value, for example 10100. My thinking is that I will create a macro for each of the 26 possible values and save as after I run each delete macro.
This report does have a header that I need to keep.
The length (number of rows) changes monthly and I'd rather not alter the macro each month.

Help?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
Sub test()
For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
    If Range("A" & i).Value <> 10100 Then Rows(i).Delete shift:=xlUp
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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