VBA Hide Rows Based on Cell Value

tlc53

Active Member
Joined
Jul 26, 2018
Messages
404
Hi there,

I'm made some progress but not quite there with this code.
It correctly hides the rows if days = 365. However, I would also like it to hide the rows if it is blank (so 365 or Blank).
Also, I have headers on Rows 26:27. I would only like these rows to be visible if any of the results <> = 365 or Blank

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Rows("28:28").Hidden = Range("I17").Value = 365
    Rows("29:29").Hidden = Range("I18").Value = 365
    Rows("30:30").Hidden = Range("I19").Value = 365
    Rows("31:31").Hidden = Range("I20").Value = 365
    Rows("32:32").Hidden = Range("I21").Value = 365
    Rows("33:33").Hidden = Range("I22").Value = 365
    Rows("34:34").Hidden = Range("I23").Value = 365
    Rows("35:35").Hidden = Range("I24").Value = 365
End Sub

Can someone help me out please? I've already spent waaaayyyyy too much time on this 😅

Thank you!!
 
Try this code and see if it works for you. You can change the B Variable if the checker row changes, and the I variable if the start row changes.
VBA Code:
Sub tlc53()
Dim B As Long, I As Long
B = 17
For I = 28 To 35
    If Range("I" & B).Value = 365 Or Range("I" & B).Value = "" Then
        Rows(I).Hidden = True
        Else
    End If
    B = B + 1
Next I
End Sub
 
Upvote 0
Give this a try. It deals with hiding & unhiding like your original code as well as the extra requirement re headings.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim r As Long

  For r = 17 To 24
    Rows(r + 11).Hidden = Range("I" & r).Value = 365 Or Len(Range("I" & r).Value) = 0
  Next r
  Rows("26:27").Hidden = Evaluate("COUNTIF(I17:I24,365)+COUNTBLANK(I17:I24)=ROWS(I17:I24)")
End Sub
 
Upvote 0
Solution
Give this a try. It deals with hiding & unhiding like your original code as well as the extra requirement re headings.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim r As Long

  For r = 17 To 24
    Rows(r + 11).Hidden = Range("I" & r).Value = 365 Or Len(Range("I" & r).Value) = 0
  Next r
  Rows("26:27").Hidden = Evaluate("COUNTIF(I17:I24,365)+COUNTBLANK(I17:I24)=ROWS(I17:I24)")
End Sub
Works like a charm! Thank you 🍀
 
Upvote 0

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