Very Long Loop

Smoakstack

Board Regular
Joined
Mar 28, 2011
Messages
79
I am looking for zeros and hiding column data to make table less cumbersome. here is my code:

Dim A as Range
Dim B as Range
Dim C as Range
Dim D as Range

For Each C In Sheets("Elevations").Range("M400:XX400")
If (C.Value = 0) Then
C.EntireColumn.Hidden = True
Else
C.EntireColumn.Hidden = False
End If
Next C

For Each B In Sheets("Elevations").Range("b9:b400")
If (B.Value = 0) Then
B.EntireRow.Hidden = True
Else
B.EntireRow.Hidden = False
End If
Next B


I have several sheets that these codes are running on, but it takes soo long. Is there a way to make it less of a wait using an array of some sort?
 
ok. got a code to work, but when I test it, it runs through and for example, on The ACM Estimate, it will hide rows b11:b37 (which is good), then it makes them visible. Any way to stop this? The code I am using is:

For i = 2 To 30
shtarr(i).Parent.Rows("1:" & Rows.Count).Hidden = False
With shtarr(i)
Set rng = .Find("0", LookIn:=xlValues, LookAt:=xlWhole)
If Not rng Is Nothing Then
Do
rng.EntireRow.Hidden = True
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing
End If
End With
Set rng = Nothing
Next i
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
ok. got a code to work, but when I test it, it runs through and for example, on The ACM Estimate, it will hide rows b11:b37 (which is good), then it makes them visible. Any way to stop this? The code I am using is:

For i = 2 To 30
shtarr(i).Parent.Rows("1:" & Rows.Count).Hidden = False
With shtarr(i)
Set rng = .Find("0", LookIn:=xlValues, LookAt:=xlWhole)
If Not rng Is Nothing Then
Do
rng.EntireRow.Hidden = True
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing
End If
End With
Set rng = Nothing
Next i

Try the adjusted code I posted a few posts ago - I had to move the shtarr(i).Parent.Rows.... line out, and I explained it in that post as well.
 
Upvote 0
ok. took out:

shtarr(i).Parent.Rows("1:" & Rows.Count).Hidden = False

Added seperate button with

Sheet1.Range("A1:XX1").EntireColumn.Hidden = False
Sheet1.Range("A1:A400").EntireRow.Hidden = False
Sheet4.Range("A1:A400").EntireRow.Hidden = False
Sheet5.Range("A1:A400").EntireRow.Hidden = False
Sheet6.Range("A1:A400").EntireRow.Hidden = False
Sheet7.Range("A1:A400").EntireRow.Hidden = False
Sheet8.Range("A1:A400").EntireRow.Hidden = False
Sheet9.Range("A1:A400").EntireRow.Hidden = False

Solved!

Thank you so much for bearing with me Mr Kowz
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

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