Modify a Macro to Repeat for all Selected Worksheets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use this macro to help name ranges.

Sub maketable()

Range("B19").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

ActiveWorkbook.Names.Add Name:=Application.InputBox("Enter Table Name")

End Sub


Is it possible to modify it so that it will run on all selected worksheets
(I select the worksheet via ctrl left click.

Thank you in advance.
 
This should do the trick. - John Michl

Sub maketable()
Set SheetList = ActiveWindow.SelectedSheets

For Each sh In SheetList
sh.Activate
Range("B19").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

ActiveWorkbook.Names.Add Name:=Application.InputBox("Enter Table
Name")
Next sh

End Sub
 
Forgot to mention that in the future, post macro questions in the
"programming" group since that's where the VBA pros hang out.

- John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top