help with code to automatically hid rows if a cell is empty

bleeet

Board Regular
Joined
May 11, 2009
Messages
208
Office Version
  1. 2013
Platform
  1. Windows
hello

i am not good with VBA but i want to make a code in one of of the pages in my excel file so that if nothing appears in a cell in the range of C4 to C23 then the row is automatically hidden and and if something appears the row unhides

dunno if this matters but those cells will show info that come from info on another sheet.

i saw this code on another thread here but i don't know how to adjust this to fit my setting


Private Sub Worksheet_Calculate()
Dim i As Long
For i = 9 To 53
Rows(i).Hidden = Range("A" & i).Value = ""
Next i
End Sub

if anyone knwo how to do this or advice on a better idea please help

i hope you guys understand what i am saying
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try

Code:
Private Sub Worksheet_Calculate()
Dim i As Long
For i = 4 To 23
    Rows(i).Hidden = Range("C" & i).Value = ""
Next i
End Sub
 
Upvote 0
Try

Code:
Private Sub Worksheet_Calculate()
Dim i As Long
For i = 4 To 23
    Rows(i).Hidden = Range("C" & i).Value = ""
Next i
End Sub

thanks VOG

but it's not working i get a run time error and it effect my other sheets i think
 
Upvote 0
i am guessing there is an error here

Rows(i).Hidden = Range("C" & i).Value = ""

since it is highlighted in yello when i press debug
 
Upvote 0
It works for me. Is the sheet protected or filtered?
right now the sheet is unprotected

i put the code by right clicking the sheet name and view code it that the right way?

not sure if fitered how do i find that out?
 
Upvote 0
Yes, you put the code in the right place.

If the sheet is filtered you will have drop down arrows in row 1.

The code will fail if there are error values like #N/A. Are there errors?
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,815
Members
448,990
Latest member
rohitsomani

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