![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 246
|
i created a command bar button in the menu bar. the code to add/delete the command bar is located in 'This Worksheet'.
the macro that is attached to the command bar button is in Module1 (simple macro). the macro basically executes some commands in the Active Worksheet (creates Names, some find/replaces...nothing difficult). for each worksheet, i have to single-click the command bar button. how do i write code so that the macro will be executed on ALL selected worksheets, not just the active worksheet. thanks in advance. mach3 |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Location: Sarasota, FL
Posts: 1,539
|
try this:
Sheets.Select then all sheets should be active Corticus |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 246
|
i don't want ALL sheets selected; i just want the macro run on selected sheets.
for example, if i have 20 sheets, but want the macro run on 18 of the 20 sheets, currently i have to select a workbook and click on the macro. i have to do this for ALL 18 sheets. i want to run the macro once after i've selected the 18 sheets. the code is actually very simple. the 2 basic things the macro does is the following: 1) ActiveWorkbook.Names.Add ActiveSheet.Name, ActiveSheet.Range("A1") this names cell A1 the name of the sheet. 2) Cells.Replace What:="Hello", Replacement:="Good-bye", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False this basically finds a word and replaces it with another word. how do i edit the code so that hitting the macro button once will execute the macro to ALL selected sheets, NOT just the active sheet? thanks. mach3 |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Location: Sarasota, FL
Posts: 1,539
|
try not specifying the sheet like this:
Range("A1:Z100").Select Selection.Replace What:="Hello", Replacement:="Goodbye", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False I tried this and it let me select pages and it only ran on the highlighted pages, Corticus |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Location: Sarasota, FL
Posts: 1,539
|
hmmm.
I see that I still missed part of your ? I'm no not sure about the naming cell A1 after the sheet for all your selected sheets, but the find and replace works Corticus |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|