Very Easy ActiveWorksheet question

lhernandez

Active Member
Joined
May 22, 2006
Messages
282
For some reason I am having problems checking if a sheet is active :rolleyes:
What I would like to do is as follows:
If Sheet1 = activeworksheet then
clear contents
end if

if Sheet2 is active then
clear (A1:D1)
end if

Can someone help me out on this simple task that I cannot get please :cry:
thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this.
Code:
Select Case ActiveSheet.Name
     Case "Sheet1"
          ActiveSheet.Cells.ClearContents
     Case "Sheet2"
          ActiveSheet.Range("A1:D1").ClearContents
End Select
 
Upvote 0
Hi lhernandez

You could use a select case statement on the activesheets name

Code:
Select Case Activesheet.name
case "Sheet1"
   'do your thing here
case "Sheet2"
  ' do something else here
case else
'   do stuff here that isnt satisfied by earlier conditions
end select

HTH

Patrick


Edit: Sorry, Norie got there first!!
 
Upvote 0
try putting this code into sheet1 code

Code:
Private Sub Worksheet_Activate()
    Cells.ClearContents
End Sub

and this in sheet2 code

Code:
Private Sub Worksheet_Activate()
    Range("A1:D1").ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

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