vba set x = range(a) ;对象 '_Global' 的方法 'Range' 失败
vba set x = range(a) ;method 'Range' of object '_Global' failed
以下代码段在 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 个 sheet 名为:“21-35”; “36-60”; "61-80".
在每个 sheet 中有一个名为 "services" & sheet 的范围。
例如 sheet "21-35" 范围是 "services21-35".
services21-35
不是有效的范围名称:我无法创建该名称,因为它包含 -
以下代码段在 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 个 sheet 名为:“21-35”; “36-60”; "61-80".
在每个 sheet 中有一个名为 "services" & sheet 的范围。
例如 sheet "21-35" 范围是 "services21-35".
services21-35
不是有效的范围名称:我无法创建该名称,因为它包含 -