编译错误-必需变量-无法分配给此表达式 [英] Compile Error - Variable Required-can't assign to this expression
本文介绍了编译错误-必需变量-无法分配给此表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我要复制的代码:
Private Sub btnRefresh_Click()
Dim W As Worksheet: Set W = ActiveSheet
Dim Last As Integer: Last = W.Range("A100").End(xlUp).Row
If Last = 1 Then Exit Sub
Dim Symbols As String
Dim i As Integer
For i = 2 To Last
Symbols = Symbols & W.Range("A" & i).Value & "+"
Next i
Symbols = Left(Symbols, Len(Symbols - 1))
Debug.print Last
Debug.print Symbols
End Sub
我很确定问题出在第三行.我原来写的是
I'm pretty sure that the issue is in the third line. I had originally written
Dim Last as Integer: Set Last = W.Rang("A100").End(xlUp).Row
我意识到 Set
仅适用于对象,因此我将其删除.现在,我收到错误消息:
I realized that Set
was only for objects and so I removed it. Now I receive the error message:
编译错误.必需变量-无法分配给该表达式.
Compile Error. Variable Required-cannot assign to this expression.
有什么不好的主意吗?
推荐答案
此行:
Symbols = Left(Symbols, Len(Symbols - 1))
您正在尝试从字符串中减去数字.我认为应该是
You're trying to subtract a number from a string. I think it should be
Symbols = Left(Symbols, Len(Symbols) - 1)
要从 Symbols
的长度中减去,当您遇到编译错误时,它将突出显示该错误所在的行.就我而言,它突出显示了减号.
To subtract from the length of Symbols
When you get a compile error it'll highlight the line that the error is on. In my case it highlighted the minus sign.
这篇关于编译错误-必需变量-无法分配给此表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文