Multiple actions

agc3278

New Member
Joined
Nov 14, 2007
Messages
15
Good Evening all,

I have this code that a wonderful user gave me some time ago below. The code below allows me to enter a number in A1 and it will show a that number of rows between the first visible row (6) and the last (43). I am hoping there is a way to add multiple actions in this code. For example, if I entered a number in B1, it will show that number between rows 44 and 54.

Any help would be greatly appreciated! Thank you.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim aNames, Val
  Dim i As Long, ShowHideRows As Long, ShowRows As Long
  
  Const sNames As String = "Sheet1, Sheet2"
  Const RowCell As String = "A1"
  Const FirstVisRow As Long = 6
  Const MaxHideRow As Long = 43
  
  If Target.Address(0, 0) = RowCell Then
    aNames = Split(sNames, ", ")
    ShowHideRows = MaxHideRow - FirstVisRow + 1
    Val = Target.Value
    ShowRows = IIf(IsEmpty(Val), ShowHideRows, Val)
    Application.ScreenUpdating = False
    For i = 0 To UBound(aNames)
      With Sheets(aNames(i)).Rows(FirstVisRow)
        .Resize(ShowHideRows).Hidden = True
        If ShowRows > 0 Then .Resize(ShowRows).Hidden = False
      End With
    Next i
    Application.ScreenUpdating = True
  End If
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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