Reputation: 79
I am trying to convert the value to the date by using the VBA, when executed the code, it showed the message
Object Required
The code as follows:
Dim wb2 As Workbook
Dim wsw As Worksheet
Dim destsheetName As String
destsheetName = "Worksheet"
Set wb2 = ThisWorkbook
Set wsw = wb2.Sheets(destsheetName)
ConvertToDate2
Sub ConvertToDate2()
Dim lastrowB As Integer
lastrowB = wsw.Cells(wsw.Rows.Count, "B").End(xlUp).Row
For i = 5380 To lastrowB
If wsw.Cells(i, 2).Value <> "" Then
wsw.Cells(i, 2).Value.NumberFormat = "dd-mm-yyyy"
End If
End Sub
I cannot figure out what the problem, would you please provide any suggestion? Thank you very much.
Upvotes: 1
Views: 1214
Reputation: 643
The error is:
wsw.Cells(i, 2).Value.NumberFormat = "dd-mm-yyyy"
The value doesn't have a Numberformat. The Numberformat
is a property of the cell (which is a Range
, and a range has a .Numberformat
)
So it should have been:
wsw.Cells(i, 2).NumberFormat = "dd/mm/yyyy"
Upvotes: 3