Worksheet Title Based on Two Cell Values

diderooy

New Member
Joined
Jan 9, 2014
Messages
21
Office Version
  1. 365
Platform
  1. Windows
I've found some great data here for using VBA to title my worksheets based on a cell's text value. But is there a way to use VBA to base a worksheet name on two different cells' text values? That is, to just combine the text of the two source cells?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
Sub updateworksheetname()
    Dim sName As String
    sName = Range("A1") & Range("B1")
    Sheets(1).Name = sName
End Sub
 
Upvote 0
Perhaps I'm using it incorrectly--it worked for my first worksheet (there are about 40 in the workbook), but for none of the others...I've highlighted all spreadsheets, and run it as a new module. Is that wrong?

Also, this is wildly different than what I used for just applying a single text value to the worksheet title (which seemed to work). I suspect there are dozens of ways to accomplish tasks, but don't know what similarities or differences I'm supposed to be looking for. This is what I had:

<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600">Sub tabname()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Activate
ws.Name = Range("$A$4").Value
Next
End Sub
</v:shapetype>
 
Last edited:
Upvote 0
I take it you want to name it based on the range in each individual sheet? These are details we need when you are initially posting.


Code:
Sub tabname()    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Name = ws.Range("A4") & ws.Range("B4")
    Next
End Sub
 
Upvote 0
Solution
I take it you want to name it based on the range in each individual sheet? These are details we need when you are initially posting.


Code:
Sub tabname()    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Name = ws.Range("A4") & ws.Range("B4")
    Next
End Sub

Thanks so much, that's perfect! Sorry about the vague request, I'm sure that's going to be a steep part of my learning curve too.
 
Upvote 0
That's alright. Just remember that the best requests are ones that tell us the problem and the desired goal/outcome in detail. You don't necessarily want to tell us how you want to get to that goal as there are likely better ways.

Glad I could help though!
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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