简体   繁体   中英

VBA rename multiple worksheets based on cells in one excel sheet and reciprocally, rename the excel cells based on excel worksheets

Thank you very much for reading this post and taking your time to answer me.

Search on prior questions and answers reveal an answer for renaming a single worksheet (or multiples) based each time on what is on each worksheet (ie to rename the worksheet based on the name inscribed in "B1"). Am looking for something a bit different please.

My sole experience with VBA consists of "copy paste commands" so would very much appreciate it if you gave out little snippets of information about what each bout of programming does in your answer :).

Am looking to use a specific excel sheet, let's call it "summary" so that modifying the name on that excel sheet modifies directly the name of each excel worksheets (they're already created), and vice versa, modifying the excel name of each worksheet would modify the content of the excel sheet "summary".

Ex: in Excel sheet "summary" cell A5 to A35 would each contain information, say "1", "2" "3" and so on until "30".

Running the macro would enable the sheets after summary ("sheet 1" sheet 2" "sheet3" until "sheet 30") to automatically be renamed "1", "2", "3" and so on.

Likewise, renaming sheet "3" into "test sheet" would automatically change the content of cell "A7" from "3" to "test sheet".

Your help would be very much appreciated.

Thank you and regards,

Johanssen

Try like below code..

Sub test()
     On Error Resume Next
     For Each oldName In ThisWorkbook.Workseets("Sheet1").Range("C1:C133")
         ThisWorkbook.Worksheets(oldName.Value).Name = oldName.Offset(0, -1).Value
     Next
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM