Excel 2016:VBA:Formula会在宏中引发语法错误


0

我的Excel数据包含F列,其格式为日期/时间:11/13/2018 9:33:00 PM现在,我需要根据公式在H列中显示该日期=TEXT(F2,("MMM-dd")) (我现在手动执行此操作工作正常)

VBA似乎可以工作,直到它达到这个公式,它会抛出我的错误: Compile Error Syntax Error

其余代码按预期工作。我尝试过替代配方,它们似乎有效。例如,如果我使用 rng.Value = "words"rng.Formula = "2+2" 宏按预期工作

无法编译的代码:


Sub test()

Dim rng As Range
Dim sht As Worksheet
Dim Lastrow As Long

Set sht = ThisWorkbook.Sheets("Sheet1")
Lastrow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

Set rng = Range("H2:H" & Lastrow)
rng.Formula = "=TEXT(F2,("MMM-dd"))"

End Sub

抱歉,如果这是一个愚蠢的问题,我是新手。任何帮助表示赞赏。


用于VBA代码的pastebin.com/jhqLXvNq后期格式很奇怪。
戴夫

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.