转换字符串,以便将其用作范围

时间:2016-12-18 22:42:55

标签: excel vba string range

我想将字符串转换为范围。

Dim operation As Integer
operation = 3
Dim contaminant As Integer
contaminant = 3
Dim countL2 As Integer 'Initial row
countL2 = 13
Dim countC2 As Integer 'Initial column
countC2 = 3

Dim maxC As String
maxC = (countC2+operation) & (countL2) & ":" & (countC2+operation) & (countL2 + contaminant - 1)
Dim maxRange As Range
Set maxRange = sh2.Range(maxC)

它不起作用。我想这是因为它没有将字符串转换为Range。

1 个答案:

答案 0 :(得分:1)

如果您尝试使用字符串指定范围,则不能将列指定为数字(除非使用R1C1表示法)。您生成的字符串等于"613:615",这对Excel没有意义。

使用以下

Set maxRange = sh2.Range(sh2.Cells(countL2, countC2 + operation), _
                         sh2.Cells(countL2 + contaminant - 1, countC2 + operation))
相关问题