Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Excel Sheet with VBA Macro

Tags:

excel

vba

I want to ask about rename the excel sheet, i want to rename the sheet with new name : older name + _v1.

So if my current sheet name is test, then I want the new name test_v1.

I only know the standard vba for rename excel sheet which is renaming excel sheet by the sheet content.

Sub Test()

Dim WS As Worksheet

For Each WS In Sheets
   WS.Name = WS.Range("A5")
Next WS
End Sub
like image 469
Ongok Ongoksepen Avatar asked Apr 01 '16 02:04

Ongok Ongoksepen


2 Answers

The "no frills" options are as follows:

ActiveSheet.Name = "New Name"

and

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

You can also check out recording macros and seeing what code it gives you, it's a great way to start learning some of the more vanilla functions.

like image 93
Realitybites Avatar answered Sep 19 '22 12:09

Realitybites


This should do it:

WS.Name = WS.Name & "_v1"
like image 38
Tim Williams Avatar answered Sep 17 '22 12:09

Tim Williams