Naming a worksheet with today's date

richarddhill

New Member
Joined
Jul 16, 2008
Messages
11
Hi all you peoiple with real skills,

I want to name a worksheet with todays date and have tried the following code only to get an error message saying "Object variable or With Block Variable not set". I am using Excel 2007

Dim WS As Worksheet

Sheets("Goods Received").Select
'and select the cells and copy them
Cells.Select
Selection.Copy
'then add a new worksheet

Sheets.Add After:=Sheets(Sheets.Count)
'and paste the values of the cell into here
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

'then select cell A1 and make the cell value todays date
Range("A1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"

WS.Name = WS.Range("A1").Text

Can anyone suggest an alternative that works? I would be most grateful.

Regards,


Richard
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I'm no VBA expert but should that be

WS.Name = WS.Range("A1").Value

You might need a function to turn it into a text date somewhere
 
Upvote 0
Hi Richard

Something like the following should work:

Code:
Dim ws As Worksheet

Set ws = Worksheets.Add

With Sheets("Goods Received")
  Union(.UsedRange,.Range("A1")).Copy
End With

ws.Range("A1").PasteSpecial xlPasteValues

ws.Name = Format(Date,"dd-mmm-yyyy")

ws.Move After:=Sheets(Sheets.Count)
 
Upvote 0
Try

Code:
Dim WS As Worksheet
Sheets("Goods Received").Copy After:=Sheets(Sheets.Count)
Set WS = ActiveSheet
With WS
    With .UsedRange
        .Value = .Value
    End With
    .Name = Format(Date, "dd-mmm-yyyy")
End With
 
Upvote 0

Forum statistics

Threads
1,216,130
Messages
6,129,058
Members
449,484
Latest member
khairianr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top