Little macro help...

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone,

In the following macro I would like to add a script instead of "'do nothing" for the Sheets HSheet and SS. How do I do this please? For instance I want to clear contents in range C3 to G3 of those two sheets.

VBA Code:
    For i = 1 To ans2
        Select Case Sheets(i).Name
            Case "HSheet", "SS"
                'do nothing
            Case Else
                Sheets(i).Unprotect "mypassword"
        End Select
    Next

Thanks and much appreciation.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
add this after Case "HSheet", "SS" :

VBA Code:
                Sheets("HSheet").Range("C3:G3").ClearContents
                Sheets("SS").Range("C3:G3").ClearContents
 
Upvote 0
Solution
add this after Case "HSheet", "SS" :

VBA Code:
ActiveSheet.Range("C3:G3").ClearContents

And if I want to clear contents only from Sheet SS and with HSheet do nothing?

I am guessing =
VBA Code:
Worksheets("SS").Range("C3:G3").ClearContents
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,668
Members
448,977
Latest member
moonlight6

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