Compile Error: Procedure too large

mlkenney0809

New Member
Joined
Jun 13, 2008
Messages
10
I am new to visual basic editor and I have a new position which right now has me copying and pasting a macro to hide all rows that contain zeros. I have attached a piece of it. There are 1,024 rows total and I got to row 479 and I get the error message.

Can you help me? It is telling me to "break up" the procedure, but I have no idea what that means or how to do it. There has got to be an easier way to do this.

Sub HideZeroCells()
If Range("g18") = "0" Then
Rows("18:18").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g22") = "0" Then
Rows("22:22").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g23") = "0" Then
Rows("23:23").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g24") = "0" Then
Rows("24:24").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g28") = "0" Then
Rows("28:28").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g29") = "0" Then
Rows("29:29").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g30") = "0" Then
Rows("30:30").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g31") = "0" Then
Rows("31:31").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g32") = "0" Then
Rows("32:32").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g34") = "0" Then
Rows("34:34").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g36") = "0" Then
Rows("36:36").Select
Selection.EntireRow.Hidden = True
End If
''
If Range("g37") = "0" Then
Rows("37:37").Select
Selection.EntireRow.Hidden = True
End If
 
Well if all the code is doing is hiding rows with 0 in column G, this would be much easier to write..Not necessarily any faster, but definately simpler

Code:
For i = 1 To 1000
    If Cells(i, "G").Value = 0 And Len(Cells(i, "G")) > 0 Then Rows(i).Hidden = True
Next i
 
Upvote 0

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.
Do you really need code?

Couldn't you use a filter?

And if you really need code couldn't you do that filter in code?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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