From: ordnance1 on 15 Apr 2010 13:49 My problem here is of course in line 1. I need the code to run based on what worksheet is active. There will be a series of these if statements (if May is active I will select May - September and so on). So is there any way to write the first line to determine the active worksheet? Sub Macro2() If Worksheets("April").Active = True Then Sheets(Array("April", "May", "June", "July", "August", "September")).Select End If End Sub
From: Wouter HM on 15 Apr 2010 14:43 Hi ordnance1, For your first line you can use: If ActiveSheet.Name = "April" Then HTH, Wouter
From: Don Guillett on 15 Apr 2010 15:04 if activeworksheet.name="April" then do this else do that end if Or instead of selecting, just do what you need to do for sheet2(Jan) to sheet13(Dec) Sub dorestofsheets() 'MsgBox ActiveSheet.Index For i = ActiveSheet.Index To 13 Sheets(i).Range("a1") = 1 Next i End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett(a)gmail.com "ordnance1" <ordnance1(a)comcast.net> wrote in message news:98E102AB-861E-4C28-AB8C-6B3260B83A15(a)microsoft.com... > My problem here is of course in line 1. I need the code to run based on > what worksheet is active. There will be a series of these if statements > (if May is active I will select May - September and so on). So is there > any way to write the first line to determine the active worksheet? > > > Sub Macro2() > > If Worksheets("April").Active = True Then > > Sheets(Array("April", "May", "June", "July", "August", > "September")).Select > > End If > > End Sub
|
Pages: 1 Prev: Macro to copy all rows between Comments Next: Automated Copy Paste |