What is wrong with this Do Until Loop? (simple)

skendzie

New Member
Joined
Oct 22, 2014
Messages
6
Thanks in advance for the time. I'm trying to set a Do Until loop and after the range sets, VBA just skips the loop. I want a macro that hides all "0" value columns. What's actually in the loop can be wrong as well, but I just want to know why VBA skips the loop.

My logic is that the range is E120. The loop should start at E120, offset, go to E121 and loop UNTIL E143. I don't get it :(

Code:
    Dim rng As Range    
    Dim col As Long
    
    
    Set rng = Range("E120")
    
    Do Until rng = Range("E143")
    col = rng
    If col = "0" Then hiderng.EntireRow.Hidden = True
            rng = rng.Offset(1, 0)
            Set rng = ActiveCell
        
    Loop
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Set rng=ActiveCell
is your undoing. Get rid of it.

You are also going to have problems with the condition

Code:
Do Until rng = Range("E143")
That line is testing if the value in rng is the same as the value in Range("E143")

I suspect that you want
Code:
Do Until rng.Address = Range("E143").address
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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