using VBA to rename active sheet

G

Guest

I am writing some vba to run some stuff. Part of this includes naming,
copying, and returning to various sheets.
I want the write a code that will rename the first sheet "Data (altered)".
I can't seem to figure out how to do that. Any help would be much
appreciated.

TIA
 
K

kkknie

If you are renaming the active sheet use:

ActiveSheet.Name = "Date (altered)"

If you are renaming the first sheet use:

Sheets(1).Name = "Date (altered)"

If you are renaming a sheet with a specific name use:

Sheets("Sheet1").Name = "Date (altered)"
 
G

Guest

Hi, what you said before is really good,

Do you know how I can make it work so that I can make Sheet1 become renamed
"1", sheet 2 is renamed "2", sheet 3 become "3" and then I can add multiple
sheets in the same sequence?

If you can help it would be much appreciated.

Thanks.
 
K

kkknie

Not sure exactly what your up to, but here's my thoughts:

Sheets("Sheet1").Name = 1
Sheets("Sheet2").Name = 2
Sheets("Sheet3").Name = 3

Or if you want to do them in a loop based on their orignal names,

Dim i As Integer

For i = 1 to 3
Sheets("Sheet" & i).Name = i
Next

If you want to just rename the sheets based on how they are currentl
ordered,

Dim i As Integer

For i = 1 To Worksheets.Count
Sheets(i).Name = i
Next

Hope this helps,
 

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

Top