In this line of code I want to insert today's date in the following format dd/mm/yyyy;…
- User
In this line of code I want to insert today's date in the following format dd/mm/yyyy; wscf.Range("I" & lastRow).Value = today's date
- Assistant
To insert today's date in the format "dd/mm/yyyy", you can use the
Formatfunction in VBA. Here's an example code snippet to accomplish that:Dim todayDate As Date Dim formattedDate As String todayDate = Date formattedDate = Format(todayDate, "dd/mm/yyyy") wscf.Range("I" & lastRow).Value = formattedDateIn this code,
todayDateis assigned the current date using theDatefunction. Then, theFormatfunction is used to convert the date into the desired format "dd/mm/yyyy", and the resulting formatted date is stored in the variableformattedDate. Finally, the formatted date is assigned to the specified cell in column "I" and the last row (lastRow) using theValueproperty of the range object. - User
can I use the following without declaring anything; wscf.Range(“I” & lastRow).Value = Format(Date, “dd/mm/yyyy”)
- Assistant
Yes, you can use the following line of code without explicitly declaring any variables:
wscf.Range("I" & lastRow).Value = Format(Date, "dd/mm/yyyy")This code uses the
Datefunction to get the current date and then formats it using theFormatfunction with the "dd/mm/yyyy" format. The resulting formatted date is directly assigned to the specified cell in column "I" and the last row (lastRow) using theValueproperty of the range object.Since the
Datefunction andFormatfunction are built-in functions in VBA, there is no need to declare any additional variables in this case.