# Visual Basic help: dynamically renaming an Excel sheet

**URL:** <https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923>\
**Category:** Factual Questions\
**Created:** [March 13, 2015, 5:12pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923 "2015-03-13T17:12:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsc1953](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jsc1953](https://boards.straightdope.com/u/jsc1953)\
**Post date:** [March 13, 2015, 5:12pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923/1 "2015-03-13T17:12:31Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [March 13, 2015, 5:18pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923/2 "2015-03-13T17:18:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jsc1953](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jsc1953](https://boards.straightdope.com/u/jsc1953)\
**Post date:** [March 13, 2015, 5:24pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923/3 "2015-03-13T17:24:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jsc1953](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jsc1953](https://boards.straightdope.com/u/jsc1953)\
**Post date:** [March 13, 2015, 5:28pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923/4 "2015-03-13T17:28:38Z")

</div>

Brilliant. Thanks!

---

<div class="post-metadata">

**Author:** ![RitterSport](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rittersport/32/6326_2.png) [@RitterSport](https://boards.straightdope.com/u/RitterSport)\
**Post date:** [March 13, 2015, 5:59pm UTC](https://boards.straightdope.com/t/visual-basic-help-dynamically-renaming-an-excel-sheet/714923/5 "2015-03-13T17:59:01Z")

</div>

Glad to help. 🙂
