View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Colin Hayes Colin Hayes is offline
external usenet poster
 
Posts: 465
Default Incrementally Updating worksheets in a workbook


Hi Garry

OK thanks again.

I'm sorry - I couldn't get this working. It gave errors I'm afraid.
Mostly protection errors , even though the sheet and the book are
unprotected. (!)

I ran it as a macro. I hope that's the correct thing to do.

I was hoping to be able to put some code under the tab to have it read
the content of B2. It does need to be volatile so it can change as the
content of B2 on each sheet changes. I think a static macro might not
achieve this so readily , but I'm not all expert.

To confuse matters , I've moved my key date from B2 to A1 , with the
first sheet just called 1. I did modify the code you sent to reflect
this.


Grateful for you help.



In article , GS writes
You're welcome!

The following revised code will rename each tab to: "mmm_yyyy").

Sub IncrementMonths()
Dim i As Integer
For i = 2 To 12
With Sheets(i)
.Range("$B$2").Formula =
"=DATE(YEAR(Sheet1!$B2),MONTH(Sheet1!$B2)+" _
& i - 1 & ",DAY(Sheet1!$B2))"
.Name = Format(.Range("$B$2").Value, "mmm_yyyy")
End With
Next
Sheets(1).Name = Format(Sheets(1).Range("$B$2").Value, "mmm_yyyy")
End Sub

If you want a different format than just edit that to suit. (I prefer
to NOT use spaces or hyphens in tab names, but that's just my personal
preference)

Doing Sheet1 last will cause Excel to update the formulas to ref the
new sheetname.