Solaire
Solaire

Reputation: 81

Format Date Error

I'm trying to place adate and time in a newly created sheet name:

 Sub errorlist()
    Sheets.Add.Name = "errorsheet" & Format(Now, "dd_mm_yyyy ss_nn_hh")
 End Sub

But vba gives me a message saying

  "compile error:
   wrong number of arguments or invalid property assignment"

What can be the problem here? Any ideas.

The code is a part of a 300 line code which i cant mention here but im sure it has no impact on the format function.

Upvotes: 0

Views: 126

Answers (1)

Dmitry Pavliv
Dmitry Pavliv

Reputation: 35863

Try to use following code:

Sub errorlist()
    Dim wb As Worksheet

    Set wb = Sheets.Add
    wb.Name = "errorsheet" & Format(Now, "dd_mm_yyyy ss_nn_hh")

End Sub

P.S. as follows from comments, OP has defined his own procedure, called Format and there was a reason why an error triggered. So, Format(Now, "dd_mm_yyyy ss_nn_hh") can be replaced with Replace(CStr(Now), "-", "_") or sth like this.

Upvotes: 2

Related Questions