如果使用VBA,如果单元格不为空,则需要更改单元格格式

时间:2018-07-23 06:33:30

标签: excel vba excel-vba

我找到了以下脚本:

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

但是有语法错误,我找不到,请帮助我。

1 个答案:

答案 0 :(得分:2)

只需将"V8" & .Rows.Count更改为"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