Invoke VBA - Write to cell

Hi,
I build a script in macro:

Function DateAndTime(RowToRead as string)
Sheet1.Range(“C”+RowToRead).Value = date.Now.ToString
End Function

What is the problem?

1 Like

@gustavo.cervelin

1 Like

Hi @Lior_Shamir

The issue is that if you want sheet1 then you have to either use

Sheets("Sheet1")

or

Worksheets("Sheet1")

but not sheet1 directly

cheers

1 Like

Thanks @Anil_G

So, it would be something like this:

Function DateAndTime(RowToRead as string)
Sheets(“Sheet1”).Range(“C”+RowToRead).Value = date.Now.ToString
End Function

If it works, kindly mark Anil’s post as solution to close the topic

Thanks!

1 Like

Hi @Anil_G @gustavo.cervelin

The problem was the date.Now.ToString
So, the correct way is:

Function DateAndTime(RowToRead as string)
Sheet1.Range(“F”+RowToRead).Value = Now
End Function

Thanks

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.