Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the address of a range to a string

Tags:

excel

vba

I have a VBA code that gives an address to an excel range that is active and selected. I am trying to get it as a string.

Sub getRange()
Dim atcSheet As Worksheet
Dim selRange As Range
Dim myRange As String

Set actSheet = ActiveSheet
Set selRange = Selection

MsgBox (selRange.Address)
myRange = selRange.Address(RowAbsolute, ColumnAbsolute)
MsgBox (myRange)
end sub

When running this (after having selected a few cells making a range), MsgBox returns the address, but i could not make it in a variable as a string.

like image 680
Cy Bu Avatar asked Dec 19 '22 08:12

Cy Bu


2 Answers

If your intention is to get the absolute reference of the range into an string variable, this will do

myRange = selRange.Address

Address(True, True) is by default.

like image 55
Subodh Tiwari sktneer Avatar answered Dec 20 '22 20:12

Subodh Tiwari sktneer


Use:

myRange = selRange.Address(True, True)
' for debug
MsgBox myRange
like image 40
Shai Rado Avatar answered Dec 20 '22 20:12

Shai Rado