VBA Excel runtime error?
When I tried to execute the below code, I got an error like "Runtime error" 424 "Required object"
Sub test()
Range("Q" & i).Text = x1.Text
End Sub
Where x1 is a calender object.
If I used the code below
Range("Q" & i) = x1.Text
My code will store the date as 02-11-2013 instead of 11-02-2013, the problem here is that it is reordering its month and date.
Hopefully I have a solution for this.
Thank you in advance
source to share
You are getting the error on the first instance as the .Text
range property is read-only and is used to get the current formatted value from the cell / range.
I would use the format function, but also set the format of the cell number you put it in, to be safe:
Range("Q" & i).Value = Format(x1.Text, "dd-mm-yyyy")
Range("Q" & i).NumberFormat = "dd-mm-yyyy;@"
Edit: In addition to your comment, I suggest trying to format the incoming date with the day and month replaced, and then apply NumberFormat like this:
Range("Q" & i).Value = Format(x1.Text, "mm-dd-yyyy")
Range("Q" & i).NumberFormat = "dd-mm-yyyy;@"
source to share