# RENAME SHEET BASED ON CELL VALUE (WITH DATE-TO-TEXT FUNCTION)



## ravecake (Dec 21, 2022)

Hi,

I need VBA code that will rename the current sheet based on the value of a cell (B2) in that sheet.

That value is a date in format YYYY-MM-DD and I need the sheet renamed in format M-D. 

Example: Cell B2 shows value "2022-12-20" -> sheet must be renamed "12-20" (excluding quotation marks).

Any help would be immensely appreciated!
Thank you.


----------



## Flashbond (Dec 21, 2022)

```
Sub renameSheet()
  Dim ws As Worksheet
  Set ws = ActiveSheet
 
  ws.Name = Format(CDate(ws.Range("B2").Value), "MM-DD")
End Sub
```


----------



## ravecake (Dec 23, 2022)

Thanks!


----------



## Peter_SSs (Dec 23, 2022)

@ravecake 
For any future questions, please note #14 of the Forum Rules regarding using all upper case in thread titles.


----------

