VBA 集合 x = 范围 (a) ;对象'_Global'的方法'Range'失败



以下代码段在Set x = Range("services" & sheetname)失败,并显示错误消息method 'Range' of object '_Global' failed 。谁能帮忙?

Sub add_Click()
    Dim sheetname As String
    Dim x As Range
    sheetname = selectSheetName(form1.age.value)
    Sheets(sheetname).activate
    Set x = Range("services" & sheetname) '<-- error here
end sub
Function selectSheetName(byval age as integer)
    If (age > 20 And age < 36) Then
        selectSheetName = "21-35"
    End If
    If (age > 35 And age < 61) Then
        selectSheetName = "36-60"
    End If
    If (age > 60 And age < 81) Then
        selectSheetName = "61-80"
    End If
End Function`

有 3 张纸,命名为:"21-35";"36-60";"61-80"。

在每个工作表中都有一个名为"服务"和工作表的范围。

例如,在工作表"21-35

"中,范围是"服务21-35"。

services21-35 不是有效的范围名称:我无法创建该名称,因为它包含-

相关内容

最新更新