Dim rng AS Range more than once

sitewolf

Active Member
Joined
May 4, 2012
Messages
304
OK, maybe I'm just not awake enough today, but I also should know more VBA than I do

I'm using VBA to delete entire rows if a specific column/cell is blank- that part is fine.
I'm using Dim rng As Range, cell As Range, del As Range.....

But after that I'd like to delete entire rows if a different column/cell is blank

What do I need to rename to be able to do both?
I thought I could just go to rng2 or something...

"Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("b1:b70000"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Value) = "" _
Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete"
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You can replace all your code with
Code:
Range("B:B").SpecialCells(xlBlanks).EntireRow.Delete
& then you can do the same thing with a different range
 
Upvote 0
Then I run into "Unable to get the SpecialCells property of the Range class" unfortunately
 
Upvote 0
Are your cells actually blank or are they formulas giving "" as a result?
 
Upvote 0
If they are not formulas, do you have a merged cells, or sheet protection?
 
Upvote 0
Are your cells actually blank or are they formulas giving "" as a result?

Data is from a csv exported from an online database- so could be both.
I've gotten around this by using the longer dim rng coding in separate macros, but would prefer to know cleaner ways to do this type of thing.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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