Simple Button Causing Problems

tkdpale

New Member
Joined
Jun 1, 2011
Messages
3
I am creating a button in excel to hide any rows that are missing data in the first column. I've got the code worked out I believe, but I can't make the button work. The code is as followed:

Sub Button74_Click()
For Each r In Range("A10:A164")
If r.Value = "True" Then
r.EntireRow.Hidden = True
Else
r.EntireRow.Hidden = False
End If
End Sub

I keep getting the error message "Compile Error: For without Next". I'm not sure what this means or how to fix it. Can somebody help?
 

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
Awesome, now I'm not getting an error, but the button doesn't hide anything. I have a logic test for each row to tell me whether or not it need hidden or not and it looks like:

=AND(ISBLANK(C10),ISBLANK(K10),ISBLANK(E10))

Example for row 10. This formula outputs either True or False. Hence why I was using the logic test in the button:

If r.Value = "True" Then

I'm not sure why it isn't hiding the cells that output True.
 
Upvote 0
I think you can simplify your code a bit by doing something like:

Code:
Dim r As Range

Application.ScreenUpdating = False


For Each r In Range("A10:A164")
r.EntireRow.Hidden = r.Value
Next r
Application.ScreenUpdating = True

Actually the simplist way would be to a filter on column A....

Nonetheless, you may want to qualify your range reference (if the button is on a different sheet than the rows you're hidding, it won't work as you expect).
 
Upvote 0
Try

Code:
Sub Button74_Click()
For Each r In Range("A10:A164")
    r.EntireRow.Hidden = r.Value = True
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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