Dim as WSS, set multiple sheets as variables, give separate command for each sheet

patsfan1

New Member
Joined
Jul 30, 2019
Messages
11
Hello,
I am attempting to put together code that will clear a range of cells from one worksheet, and then a separate range from another worksheet afterward. I'm getting a compile error, "wrong number of arguments/invalid property assign". I am not exactly clear on how to set the worksheets as variables and then assign the commands to clear the ranges. Any help is appreciated. Thanks

Code:
Private Sub CommandButton2_Click()
 
Application.ScreenUpdating = False
 
      Dim Wss As Worksheet
      
      Sheets("Sheet1").Visible = True
      Sheets("Rent Roll").Visible = True
      
      Set Wss = Sheets("Sheet1", "Rent Roll")
      With ws("Sheet1")
      
      Range("a2:q31").<wbr>ClearContents   'Clear Sheet 1 Tab
      
      With ws("Rent Roll")
      
      'Clear Rent Roll Tab
         
      Range("D6:H35").<wbr>ClearContents
      Range("J6:J35").ClearContents
      Range("M6:M35").ClearContents
      Range("R6:R35").ClearContents
      Range("T6:U35").ClearContents
      Range("x6:y35").ClearContents
      Range("aa6:ab35").<wbr>ClearContents
      Range("ae6:ag35").<wbr>ClearContents
      
      End With
    End with
    
        Wss.Visible = xlSheetVeryHidden
    
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
How about
Code:
Private Sub CommandButton2_Click()
 
Application.ScreenUpdating = False
 
      With Sheets("Sheet1")
         .Visible = True
         .Range("a2:q31").ClearContents   'Clear Sheet 1 Tab
         .Visible = xlSheetVeryHidden
      End With
      With Sheets("Rent Roll")
          .Visible = True
         'Clear Rent Roll Tab
         .Range("D6:H35").ClearContents
         .Range("J6:J35").ClearContents
         .Range("M6:M35").ClearContents
         .Range("R6:R35").ClearContents
         .Range("T6:U35").ClearContents
         .Range("x6:y35").ClearContents
         .Range("aa6:ab35").ClearContents
         .Range("ae6:ag35").ClearContents
         .Visible = xlSheetVeryHidden
      End With
End Sub
 
Upvote 0

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