Option Explicit Sub add_Sheet_name() Dim sShtName As String Sheets(“SAVER”).Select sShtName = Sheet4.Cells(3, 1).Value If Not WksExists(sShtName) Then Worksheets.Add After:=Worksheets(Worksheets.Count) ActiveSheet.Name = sShtName ActiveSheet.Range(“A1:Z150”).Value = Sheets(“SAVER”).Range(“A1:Z150”).Value ActiveSheet.Range(“A1:Z150”).Format = Sheets(“SAVER”).Range(“A1:Z150”).Format End Sub Function WksExists(wksName As String) As Boolean On Error Resume Next WksExists = CBool(Len(Worksheets(wksName).Name) > 0) End Function
The above code, ( not mine ) will add a new sheet and name the sheet according to a cell range
in Sheets(SAVER). Usually the date being yyyymmdd-“reference code”
However, the new sheet is blank and the way this code is writen, no matter what sheet name it is, it will look for the sheet’s original number. In this case it’s Sheet4, even if I do re-name it “SAVER”.
In the VBA Project Window it shows “Sheet 4 ( SAVER )” and in Cell A3 is where the new sheet gets it’s
reference to name it.
No problems there, I have worked around it, some extra coding but it will do for now.
However, I need to fill the new blank re-named worksheet with the new data, and then it’s finally saved.
The workbook is in fact “storage” for later use if need be. ( it’s not important right now )
What’s important is to be able to read it if need be.
The method I use is with the following code to transfer the data to the new worksheet, but the new worksheet has no format.
So I figured, logic would assume if
ActiveSheet.Range(“A1:Z150”).Value = Sheets(“SAVER”).Range(“A1:Z150”).Value
Does work, why then does not the following code work to not only equal the Value between
A1:Z150, but also the Format ?
ActiveSheet.Range(“A1:Z150”).Format = Sheets(“SAVER”).Range(“A1:Z150”).Format
How can I transfer the format from sheet SAVER to the newly named worksheet ?
Thanks in advance
XP