any way to rename a sheet in VBA?

dnickelson

Board Regular
Joined
Oct 30, 2003
Messages
118
I'm looking to run some queries in VBA and would like the results to come back on a sheet named with a specific part of the query (store number or such). I've searched through the message board but searching for sheet name either returns around 1500 or no matches. Anyone know of a simple example to change a sheet name in VBA. Creating a sheet would work also, may even be better. Not too worried about the format, the simpler the better, I should be able to slip it in where needed.

thanks in advance

Dan
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Do you mean some VBA code like:

ActiveSheet.Name = "New Name"
 
Upvote 0
If it's the active sheet then use
ActiveSheet.Name = "qwser"

else use

Sheets("Sheet2").Name = "adsf"

... and check out the macro recorder - it's very useful!!
 
Upvote 0
This will rename a sheet;

Sheets("Sheet5").Name = "Myname"

This will add a sheet, then rename it;

Sheets.Add
Sheets(ActiveSheet.Name).Name = "MyNewSheet"
 
Upvote 0
You can also do it by reference, without even knowing the name of sheet currently. For example, if you wanted to rename the 2nd sheet:

Sheets(2).Name = "New Name"
 
Upvote 0
Okay, I'll try coming up with a 'real' question for you guys sometime. (I'm sure questions like these are good for a laugh sometimes, though)

Thanks for the impressive response on any hand.

Dan
 
Upvote 0
just discovered that this work also!

Code:
Sheets.Add.Name = "fred"


anything to save time!!!
 
Upvote 0
how about moving a sheet (to between 2 other specified sheets, to beginning or end, to 7th in line, etc.

A link to some other reference, or some keywords to search for in help would work also.

Thanks again.
 
Upvote 0
Any one of these;

Move first to the end:
Sheets(1).Move after:=Sheets(Sheets.Count)

Move first to after Sheet2 (can change to before):
Sheets(1).Move after:=Sheets("Sheet2")

Move first to after third:
Sheets(1).Move after:=Sheets(3)
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top