filter and delete with variable name used not working

thelad

Board Regular
Joined
Jan 28, 2011
Messages
245
Hi,

I have macro working whereby it will delete all rows that have less than number four in column E.

However I want a variable to be set in stead of me inputting 4 in the code however it is not working when i set a variable. Any ideas? if you need full code let me know

Below is not full code but the "<HeroName" is not working but "<4" is?

Dim HeroName As String
HeroName = Range("E4").Value (Value is 4 in this cell)
DeleteValue = "<HeroName"
'DeleteValue = "<4" (works when i do this)

Filter code below and it works

.Range("E1:E" & .Rows.Count).AutoFilter Field:=1, Criteria1:=DeleteValue
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this:
Code:
Sub Filter_Me()
'Modified 4-3-18 12:02 AM EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Dim HeroName As Long
HeroName = Range("E4").Value
With Range("E1:E" & Lastrow)
     .AutoFilter 1, Criteria1:="<" & HeroName
     .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With
Application.ScreenUpdating = True
End Sub
 
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