Set name of worksheet in vba

Cuzzaa

Board Regular
Joined
Apr 30, 2019
Messages
86
Hi everyone

I have been using the below code to automatically hide rows based on if a cell is = 0. This works fine as I'm hiding the data on the same worksheet, but now I am using the button on my main worksheet but want to hide rows on another worksheet called 'Hidden' in the same workbook.

Please can someone help me where and how I set the name of the worksheet that I want rows to be hidden?

Code:
  Dim xRg As Range    Application.ScreenUpdating = False
        For Each xRg In Range("I22:I45")
            If xRg.Value = "0" Then
                xRg.EntireRow.Hidden = True
         
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True

Thank you so much
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Re: Help please - how to set name of worksheet in vba

If you use just Range VBA will evaluate that to ActiveSheet.Range so for a specific sheet use:

Code:
For Each xRg In Sheets("Hidden").Range("I22:I45")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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