how to hide rows based on a value in a column

maureenboyd60

New Member
Joined
May 4, 2021
Messages
9
Office Version
  1. 2016
Hello:
Thanks in advance for your help! I am new to VBA so my question may be quite simple! I have a range of data (Columns A:I) and an indeterminate number of rows. If the value in Column H = "complete' or "closed" I want to hide that row. Once the row is hidden, would it still show up in a search? I tried copying a macro I found on your site but it is not working. I assume I did not make the proper adjustments.
this is the macro I copied and tired to change. (I only tried it where cell in Column H = "complete"). The bolded row is where I believe the error is.

thanks!

Private Sub Worksheet_Calculate()

Dim lc As Long
Dim c As Long

' First unhide all rows
Cells.EntireRow.Hidden = False
' Find last row in column 8 with data
lc = Cells(8, Rows.Count).End(xldown).Row
' Loop through column 8 and hide all columns with "complete"
Application.ScreenUpdating = False
For c = 1 To lc
If Cells(8, c).Value = "complete" Then Cells(8, c).EntireRow.Hidden = True
Next c
Application.ScreenUpdating = True

End Sub
 
Something else just occurred to me.
"Worksheet_Calculate" code is event procedure code that runs automatically.
So you actually should not be able to "step into it", or run it manually.
You said the code is in the "Sheet1" module, right?
HI:
The test macro ran correctly. Yes the macro is in Sheet1. I had the filter tool turned on in the spreadsheet so I turned that off and I was able to see the Compile VBA project option. When I click it for either macro, I do not get any messages so I assume it compiled correctly?
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Something else just occurred to me.
"Worksheet_Calculate" code is event procedure code that runs automatically.
So you actually should not be able to "step into it", or run it manually.
You said the code is in the "Sheet1" module, right?
Hi:
I was able to step into the macro and the error displayed right after I pressed F8 to continue:
1620153088512.png
 
Upvote 0
It looks like you are still using your original version of the code instead of using the updated code I gave you!
Try using the code that I gave you.
Copy and paste my version of the code, so as to not make any typos.
 
Upvote 0
I put a watch on that line and noticed that the 'c' variable was 'out of context (in watch window at bottom)
View attachment 38061
That is because you are using your original bad code and not my updated code (see my previous post)!

"Rows.Count" takes you down to the last possible row on the sheet. You cannot do down from there!
 
Upvote 0
It looks like you are still using your original version of the code instead of using the updated code I gave you!
Try using the code that I gave you.
Copy and paste my version of the code, so as to not make any typos.
OMG! sorry about that! With all the cutting and pasting, I somehow pasted back in the old version! It is now working! Thanks so much for your patience. I learned a lot! Take care.
 
Upvote 0

Forum statistics

Threads
1,215,790
Messages
6,126,926
Members
449,349
Latest member
Omer Lutfu Neziroglu

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