Home » excel » excel – I need to change cell format if cell is not empty using VBA

excel – I need to change cell format if cell is not empty using VBA

Posted by: admin May 14, 2020 Leave a comment

Questions:

I found the following script:

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long
    Set ws = ThisWorkbook.Sheets("Template Allocation")

    With ws
    lRow = .Range("V8" & .Rows.Count).End(xlUp).Row
        .Range("V8:V" & lRow).NumberFormat = "dd/mm/yyyy"
    End With
End Sub

But there is syntax error, which i could not find, please, help me.

How to&Answers:

Just change "V8" & .Rows.Count to "V8:V" & .Rows.Count

With ws
    lRow = .Range("V8:V" & .Rows.Count).End(xlUp).Row
        .Range("V8:V" & lRow).NumberFormat = "dd/mm/yyyy"
 End With