Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Set variable to active cell address

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shelfish - 21 Nov 2007 02:45 GMT
I just need to set the value of a variable to the "A1" address of the
active cell. I feel like I've tried everything, but shouldn't this
work....

Dim rng as Range

Set rng = activecell                   [results in active cell's
value]
Set rng = activecell.address    [throws error]

Thanks all,
Shelton.
JLGWhiz - 21 Nov 2007 03:06 GMT
rng = ActiveCell  gives value
rng = ActiveCell.Address gives cell reference in A1 format
Set rng = ActiveCell is used to set the active cell as an object variable
range
then you cans do: x = rng.address to get a cell string in A1 format.

I get screwed around on these also.  The best way to do it is to use a Range
or Cells reference if you can.  If you have to have a variable, then don't
forget that it is a cell reference and you will need to use it like
Range(rng) when setting a range reference.

> I just need to set the value of a variable to the "A1" address of the
> active cell. I feel like I've tried everything, but shouldn't this
[quoted text clipped - 8 lines]
> Thanks all,
> Shelton.
OssieMac - 21 Nov 2007 03:07 GMT
Hi,

Dim rngAddr As String
Dim rng As Range

Set rng = ActiveCell

rngAddr = rng.Address          'returns $A$1
rngAddr = rng.Address(0, 0)  'returns A1
rngAddr = rng.Address(0, 1)  'returns $A1
rngAddr = rng.Address(1, 0)  'returns A$1

'Use address like this

Range (rngAddr)

Signature

Regards,

OssieMac

> I just need to set the value of a variable to the "A1" address of the
> active cell. I feel like I've tried everything, but shouldn't this
[quoted text clipped - 8 lines]
> Thanks all,
> Shelton.
shelfish - 21 Nov 2007 06:32 GMT
> Hi,
>
[quoted text clipped - 29 lines]
> > Thanks all,
> > Shelton.

Brilliant! Thanks for the help.
Dave Peterson - 21 Nov 2007 03:09 GMT
dim myAddr as string
myAddr = activecell.address(0,0)

> I just need to set the value of a variable to the "A1" address of the
> active cell. I feel like I've tried everything, but shouldn't this
[quoted text clipped - 8 lines]
> Thanks all,
> Shelton.

Signature

Dave Peterson

shelfish - 21 Nov 2007 18:41 GMT
Very nice that you did this in one step. I knew it couldn't be a two-
step process. Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.