View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dr Dan[_2_] Dr Dan[_2_] is offline
external usenet poster
 
Posts: 19
Default If sheet name contains 'A' run macro1, if 'B' run macro 2?

I tried it but and it looked very busy for a while. Once finishhed I realised
it had plotted 144 graphs all in the same, first worksheet, using either
macro A or B to give 2 different formattings amongst the plots. The remaining
sheets had no plots on them.

It looks as though it examined all the tab names but did not actually move
into each sheet and look at new data.

Cheers,

Dan

Here's the code I used...
Sub plotallsheets()
'
' plotallsheets Macro
' Macro recorded 23/02/2007 by Dan
'
' Keyboard Shortcut: Ctrl+l


Dim SheetName

For Each SheetName In Sheets
If InStr(1, SheetName.Name, "A") 0 Then
plotchronoamperometry
GoTo ReStart:
End If

If InStr(1, SheetName.Name, "B") 0 Then
plotIVcurve
GoTo ReStart:
End If

If InStr(1, SheetName.Name, "C") 0 Then
plotchronoamperometry
GoTo ReStart:
End If

ReStart:
Next SheetName
End Sub




"DaveO" wrote:

Hi, Dan-
This code will do it:

Sub AllTabs()
Dim SheetName

For Each SheetName In Sheets
If InStr(1, SheetName.Name, "A") 0 Then
Macro_A
goto ReStart:
end if

If InStr(1, SheetName.Name, "B") 0 Then
Macro_B
goto ReStart:
end if

ReStart:
Next SheetName
End Sub

Substitute your macro names for Macro_A and Macro_B.

This code will run against ALL tabs in the workbook, and hidden tabs
may cause a runtime error.

Dave O