Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy cell to variable (Excel XP)

    Cell A1 has a formula which tells me the month and year. I want to copy the result of that formula to a variable.

    How can I do this?

    I tried:
    Dim mrg As Variant
    mrg = Selection.Range

    but that only works in Word.

    Any help is appreciated! Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy cell to variable (Excel XP)

    Dim mrg As Variant
    mrg = Range("A1").Value

    or if you are certain that A1 is selected:

    mrg = ActiveCell.Value

    but in general, it is better to refer to ranges with cell addresses (or to named ranges) than to keep on moving the active cell in code in order to get its value.

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy cell to variable (Excel XP)

    Terrific, thanks Hans, much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •