Unhide/Hide a range of Rows on Another Worksheet Based on Cell Values

Sanchez88

New Member
Joined
Oct 16, 2017
Messages
7
Hello to anyone willing to help me,

There's many threads on this but none that help my case (which might be simple but i'm not familiar enough with VBA to do it myself.)

I want the Macro to Unhide Rows based on two different Cells in another worksheet.

For example:

Sheet 1 E41 = 1
Sheet 1 F41 = 5

Sheet 2 Rows (x:x) Unhide
Sheet 2 Rows (y:y) Hide

To clarify i have my version (which has not been working) below.

I've tried "Dim" as Integers too and it hasn't worked.
Any help would be greatly appreciated, i have no other ideas...

Code:
Private Sub CommandButton2_Click()

    Dim i As String
    Dim j As String
    Dim k As String
        
    i = ActiveSheet.Cell(E41).Value + 8
    j = ActiveSheet.Cell(F41).Value + 8
    k = ActiveSheet.Cell(F41).Value + 9
    
    Worksheets("Caller 1").Rows("i:j").Hidden = False
    Worksheets("Caller 1").Rows("k:38").Hidden = True


End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
not 100% sure I understand but try this.

Code:
Sub hide_rows()


With Worksheets("Caller 1")
.Rows(Range("E41").Value + 8).Hidden = False
.Rows(Range("F41").Value + 8).Hidden = False
.Rows(Range("F41").Value + 9).Hidden = True
End With

End Sub

hth,

Ross
 
Upvote 0
Yea sorry, I'm not the best at explaining.

That is kind of what I want, but would it be possible to make it ranges?

For example:
Code:
Sub hide_rows()


With Worksheets("Caller 1")

    Rows(Worksheets("Hourly Vote Tally Sheet").Range("E41").Value + 8 : "Hourly Vote Tally Sheet").Range("F41").Value + 8).Hidden = False
    Rows(Worksheets("Hourly Vote Tally Sheet").Range("F41").Value + 9 : 38).Hidden = True

End With

End Sub

Basically the two Cells in "Hourly Vote Tally Sheet", E41 & F41 determine the range of Rows that Reveal in "Caller 1".

For Example

E41 F41
1 - 5

Rows 9 - 13 Unhide

Does that help at all?
 
Upvote 0
Code:
Sub hide_rows()
Dim ws1 As Worksheet, ws2 As Worksheet

Set ws1 = Worksheets("Hourly Vote Tally Sheet")
Set ws2 = Worksheets("Caller 1")


ws2.Rows("10:38").Hidden = True 'undie rows as neede

i = ws1.[E41] + 8
j = ws1.[F41] + 8

ws2.Rows(i & ":" & j).Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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