sheet namimg macro

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

Guest

I have a set of worksheets (200) that all have the same name, and they all
need to be changed to a name that is in the same cell address. The sheet
names are all 4631 and in cell A2 in every sheet is the full name ex.
"4631-02-09"

I am wondering if there is a way a macro can do this?


Todd
 
I can't guarantee success but someting along the lines of the below
should work:

Dim OriginalName as String
Dim NewName as String

For x = 1 To ThisWorkbook.Worksheets.Count
OriginalName=ActiveSheet.Name
NewName = OriginalName & Range("A1").Value
ActiveSheet.Name = NewName
Next x

Change the Range("A1") to be the range of whatever the common cell is
and if needed change this formula so it puts the original name etc. in
a different order.

Should work.
 
I don't understand the point of the loop. It looks like you are changing the
name of the active sheet over and over. You'd have to activate each sheet at
the beginning of the code (in order to process every worksheet in the
workbook) or change ActiveSheet to Worksheets(x) (and fully qualify the
range as Worksheets(x).Range("A1"). A For/Each loop would also work:

Dim WkSht As Worksheet
For each WkSht in Worksheets
WkSht.Name = WkSht.Name & WkSht.Range("A1").Value
Next WkSht
 

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