Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default If/Then Macro For Each Visible Worksheet

I have a workbook that will always contain at least one visible worksheet.
The number of visible worksheets may vary, but the workbook will always
contain at least one visible and one hidden worksheet.

I would like to add the following logic to run with an on open workbook
event but am having a hard time piecing together the proper VB code.

On Workbook Open,
For each visible worksheet within the workbook,
IF cell A1="Input",
THEN run formatting macro,
ELSE do nothing.

Any help is much appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default If/Then Macro For Each Visible Worksheet

Mike, test each worksheet to see if it is visible:

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Visible = xlSheetVisible Then
If ws.Range("A1") = "Input" Then
formatting_macro
End If
End If
Next
End Sub

replace "formatting_macro" with the name of your macro
--
Charles Chickering

"A good example is twice the value of good advice."


"Mike G - D.C." wrote:

I have a workbook that will always contain at least one visible worksheet.
The number of visible worksheets may vary, but the workbook will always
contain at least one visible and one hidden worksheet.

I would like to add the following logic to run with an on open workbook
event but am having a hard time piecing together the proper VB code.

On Workbook Open,
For each visible worksheet within the workbook,
IF cell A1="Input",
THEN run formatting macro,
ELSE do nothing.

Any help is much appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default If/Then Macro For Each Visible Worksheet

give this a try... It must go into the thisworkbook module. Right click the
XL icon next to the word file in the XL menu and select View Code. Paste the
following

Private Sub Workbook_Open()
Dim wks As Worksheet

For Each wks In Worksheets
If wks.Visible = xlSheetVisible Then
MsgBox "Format sheet " & wks.Name
End If
Next wks
End Sub
Not that this code is not activating the sheet...
--
HTH...

Jim Thomlinson


"Mike G - D.C." wrote:

I have a workbook that will always contain at least one visible worksheet.
The number of visible worksheets may vary, but the workbook will always
contain at least one visible and one hidden worksheet.

I would like to add the following logic to run with an on open workbook
event but am having a hard time piecing together the proper VB code.

On Workbook Open,
For each visible worksheet within the workbook,
IF cell A1="Input",
THEN run formatting macro,
ELSE do nothing.

Any help is much appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default If/Then Macro For Each Visible Worksheet

Sorry I missed the whole A1 = Input thing ... Try this...

Private Sub Workbook_Open()
Dim wks As Worksheet

For Each wks In Worksheets
If wks.Visible = xlSheetVisible And _
UCase(wks.Range("A1").Value) = "INPUT" Then
MsgBox "Format sheet " & wks.Name
'wks.select 'Select the sheet if necessary
End If
Next wks
End Sub
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

give this a try... It must go into the thisworkbook module. Right click the
XL icon next to the word file in the XL menu and select View Code. Paste the
following

Private Sub Workbook_Open()
Dim wks As Worksheet

For Each wks In Worksheets
If wks.Visible = xlSheetVisible Then
MsgBox "Format sheet " & wks.Name
End If
Next wks
End Sub
Not that this code is not activating the sheet...
--
HTH...

Jim Thomlinson


"Mike G - D.C." wrote:

I have a workbook that will always contain at least one visible worksheet.
The number of visible worksheets may vary, but the workbook will always
contain at least one visible and one hidden worksheet.

I would like to add the following logic to run with an on open workbook
event but am having a hard time piecing together the proper VB code.

On Workbook Open,
For each visible worksheet within the workbook,
IF cell A1="Input",
THEN run formatting macro,
ELSE do nothing.

Any help is much appreciated.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to create a shortcut to make next Worksheet visible nde Excel Programming 3 March 5th 07 03:31 PM
Worksheet has to set to visible as it is not visible after saving and closing Excel by VB. Oscar Excel Programming 6 June 21st 05 10:39 PM
print different worksheet by pressing visible button on worksheet Confused Excel Worksheet Functions 2 June 13th 05 02:22 PM
Macro for Hiding Visible Worksheet LDanix Excel Programming 2 October 29th 04 08:21 PM
Macro to enable or visible on specific worksheet only Edgar Excel Programming 4 May 31st 04 07:26 AM


All times are GMT +1. The time now is 07:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"