简体   繁体   English

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

[英]I need to change cell format if cell is not empty using VBA

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. 但是有语法错误,请帮帮我,我找不到。

Just change "V8" & .Rows.Count to "V8:V" & .Rows.Count 只需将"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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM