VBA to delete row based on cell value

dumbitdown

New Member
Joined
Jul 23, 2007
Messages
28
I'm trying to get some code to help me delete rows from a data set when a value in column I = 2016, everything I've seen so far just ends up deleting all rows of data, now those that I've tried to specify as having 2016 in column I

There are several hundred rows of data and it gets refreshed with new stuff on a fairly regular basis so there is no defined volume of records in the list that is being used.

Would someone be able to provide me with some code to help with this?

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is that all that is in column "I" just "2016"

So look through all rows and any row that has "2016" in Column "I" then delete that row.

Is that what you want?

And your willing to use Vba?

This cannot just be done with a just a formula.
 
Upvote 0
Upvote 0
Yeah sorry, I should have included that, I am trying to use VBA to delete the row.

Column I contains multiple values but I only want to delete those rows that have 2016 in it.
 
Upvote 0
Try this:

Code:
Sub FilterMini()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "I").End(xlUp).Row
With ActiveSheet.Range("I1:I" & Lastrow)
.AutoFilter Field:=1, Criteria1:="2016", Operator:=xlFilterValues
.SpecialCells(xlCellTypeVisible).Rows.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
Yeah sorry, I should have included that, I am trying to use <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: dotted; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(0, 0, 0); border-left-color: initial; border-image: initial; cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> to delete the row.
You did. It is right in your title!;)
 
Upvote 0
The script is correct to assume that, it's not date related it's an outcome code that means those records can be removed.

The filter itself works, however I'm getting an error message when it's trying to delete, when I select debug it's highlighting

.SpecialCells(xlCellTypeVisible).Rows.Delete

Any thoughts?
 
Upvote 0
You may want to take a look at the links I provided, as I think the code provided here does not account for the header row (if there is one), and it will delete that too.
 
Upvote 0

Forum statistics

Threads
1,215,769
Messages
6,126,787
Members
449,336
Latest member
p17tootie

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