Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Excel vba macro string and date

I want to specify a word plus a date in a cell.

Sub CurrentTestCell()
    With Range("i2")
    .Value = ("Test") And Date
    .NumberFormat = "mmmm yyyy"
  End With
End Sub

The code without the ("Test)" And works and shows the current date.
The field should show i2 "Test Dezember 2021"

Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Run-time error ’13’: Type mismatch

>Solution :

Date format will not work on text data. You need format function for dates. Try-

Sub CurrentTestCell()
    With Range("I2")
    .Value = "Test " & Format(Date, "mmmm yyyy")
  End With
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading