我很难检索超过255个字符的range.address。 我的范围包含多个碎片范围,其地址如下所示: “A1:B3,C4,K7:T6,A3:D3”
目前我正在处理地址超过1000个字符的范围。可悲的是我无法使用range.address获取完整地址。我的第一个角色只有255个。
感谢任何帮助:)
顺便说一下,我已经阅读了Microsoft在http://support.microsoft.com/kb/105416上传递长度超过255个字符的字符串的工作。但这是关于传递字符串,而不是关于返回字符串,所以......是的。
答案 0 :(得分:2)
我没有意识到范围地址长度有限制。与@Rory解决方案类似,我遍历范围区域,但我的解决方案使用返回长地址字符串的函数。
Function LongSelectionAddress(rngToGetAddress As Range) As String
Dim LongAddress As String, rngArea As Range
For Each rngArea In rngToGetAddress.Areas
LongAddress = LongAddress & rngArea.Address & ","
Next rngArea
LongSelectionAddress = Left(LongAddress, Len(LongAddress) - 1)
End Function
答案 1 :(得分:0)
我不知道地址会有什么用处,但你可以通过遍历范围区域来获取它:
Sub bar()
Dim n As Long
Dim rg As Range
Dim rgArea As Range
Dim sAddress As String
For n = 1 To 500
If n = 1 Then
Set rg = Cells(n, 1)
Else
Set rg = Union(rg, Cells(n * 2, 1))
End If
Next n
For Each rgArea In rg.Areas
sAddress = sAddress & "," & rgArea.Address
Next rgArea
MsgBox Len(sAddress)
End Sub