Visual Basic help: dynamically renaming an Excel sheet

Whenever I need a macro I just turn on the recorder, and sometimes I’m able to interpret and edit the results. But this one has me stumped.

I have .xls spreadsheet. The worksheet has a generic name (let’s say “Worksheet 1”.) I want the macro to select the contents of a cell on that worksheet – let’s say cell B12 contains some data that varies each time. I want the contents of B12, plus some hardcoded text value (for example “Results”), to become the name of the worksheet.

So if B12 contained “Q1 2015” I want the macro to change the name of the sheet from “Worksheet 1” to “Q1 2015 Results”

The results I get from the macro recorder seem to hardcode the B12 contents into the macro. It needs to be dynamic.

Thanks!

ThisWorkBook.Sheets(“Worksheet 1”).name = ThisWorkBook.sheets(“Worksheet 1”).range(“B12”).value & " Results"

I was so close! I had something similar but got an error – I wasn’t using .range.value.

I’ll try it and report back.

Brilliant. Thanks!

Glad to help. :slight_smile: