Deleting Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,605
Office Version
  1. 2021
Platform
  1. Windows
I am trying to write VBA to delete data in column A containing the reference "BUD + the current month for eg BUD0806. Next month the reference could be BUD0906. As can be seen the BUD reference can change. I need VBA code to cater for the change and there to delete the entire row containg the code beginning with BUD

I have used the following code, but cannot get it to work

LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 2 Step -1
If Cells(i, "A").Value = "BUD*.*" Then Cells.Rows(i).Delete
Next i

Your assistance will be most appreciated.

Howard
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this:

Code:
LastRow = Range("A65536").End(xlUp).Row 
For i = LastRow To 2 Step -1 
    If Left(Cells(i, "A"),3) = "BUD" Then Rows(i).EntireRow.Delete 
Next i
 
Upvote 0
Deleting Rows

Thanks for the help.

The VBA code works perfectly.




Howard
 
Upvote 0

Forum statistics

Threads
1,226,227
Messages
6,189,753
Members
453,567
Latest member
kentbarbie

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