我有一个VBA脚本,它应该检查范围中的单元格值是否以","结尾。如果是,则删除逗号。
Dim Bereich As Range
Dim Zeilen As Long
Dim Zelle As Range
Dim str As String
Zeilen = Cells(Rows.Count, 1).End(xlUp).Row
Set Bereich = Range(Cells(4, 3), Cells(Zeilen, 19))
For Each Zelle In Bereich
str = Zelle.Value
If str.EndsWith(",") Then
str = Left(str, Len(str) - 1)
Zelle.Value = str
End If
Next Zelle
然而,在行
If str.EndsWith(",") Then
我收到错误消息"无效标识符"。但我在剧本里找不出毛病。非常感谢你的帮助!
如注释中所述,VBA与VB不同;字符串数据类型在VBA中没有属性或方法。
在这种情况下,更改
If str.EndsWith(",") Then
至
If Right$(str, 1) = "," Then
旁注:考虑使用与str
不同的变量,因为这会遮挡Str
函数。