+ Reply to Thread
Results 1 to 9 of 9

How do I assign the value in a cell to a variable?

  1. #1
    JasonK
    Guest

    How do I assign the value in a cell to a variable?

    I'm sure this is easy for someone, TIA.

    I need a macro to search a range of cells (I can do that) and find a
    cell with a value (which can change) verses other cells that have no
    value. I can make the macro select the cell and copy it, but i need to
    assign the value the macro finds in that cell to a variable. Does the
    copied value in the clipboard have a name?

    Thanks again,
    Jason

  2. #2
    Raman
    Guest

    Re: How do I assign the value in a cell to a variable?

    You can create a variable in VBA and assign it the value of the cell
    using the activeccell.value property

    You can assign value when you track the cell with value

    Your code could be
    dim x 'declare a variable
    x=activecell.value 'assing the variable the value of cell

    For more,post your questions on
    http://groups.google.co.in/group/answers-for-everything


  3. #3
    Raman
    Guest

    Re: How do I assign the value in a cell to a variable?

    You can create a variable in VBA and assign it the value of the cell
    using the activeccell.value property

    You can assign value when you track the cell with value

    Your code could be
    dim x 'declare a variable
    x=activecell.value 'assing the variable the value of cell

    For more,post your questions on
    http://groups.google.co.in/group/answers-for-everything


  4. #4
    Raman
    Guest

    Re: How do I assign the value in a cell to a variable?

    You can create a variable in VBA and assign it the value of the cell
    using the activeccell.value property

    You can assign value when you track the cell with value

    Your code could be
    dim x 'declare a variable
    x=activecell.value 'assing the variable the value of cell

    For more,post your questions on
    http://groups.google.co.in/group/answers-for-everything


  5. #5
    Raman
    Guest

    Re: How do I assign the value in a cell to a variable?

    You can create a variable in VBA and assign it the value of the cell
    using the activeccell.value property

    You can assign value when you track the cell with value

    Your code could be
    dim x 'declare a variable
    x=activecell.value 'assing the variable the value of cell

    For more,post your questions on
    http://groups.google.co.in/group/answers-for-everything


  6. #6
    JasonK
    Guest

    Re: How do I assign the value in a cell to a variable?


    thanks again. that worked great. i'm slowly learning this stuff.




    On 13 Mar 2006 23:23:42 -0800, "Raman" <[email protected]> wrote:

    >You can create a variable in VBA and assign it the value of the cell
    >using the activeccell.value property
    >
    >You can assign value when you track the cell with value
    >
    >Your code could be
    >dim x 'declare a variable
    >x=activecell.value 'assing the variable the value of cell
    >
    >For more,post your questions on
    >http://groups.google.co.in/group/answers-for-everything



  7. #7
    JasonK
    Guest

    Re: How do I assign the value in a cell to a variable?


    thanks again. that worked great. i'm slowly learning this stuff.




    On 13 Mar 2006 23:23:42 -0800, "Raman" <[email protected]> wrote:

    >You can create a variable in VBA and assign it the value of the cell
    >using the activeccell.value property
    >
    >You can assign value when you track the cell with value
    >
    >Your code could be
    >dim x 'declare a variable
    >x=activecell.value 'assing the variable the value of cell
    >
    >For more,post your questions on
    >http://groups.google.co.in/group/answers-for-everything



  8. #8
    Rookie_User
    Guest

    Re: How do I assign the value in a cell to a variable?

    That works if you know or have the active cell what you want. But lets say
    you have six variables and you know of six different cells that have
    information you want. Can you assign the values of those into the different
    variables..

    maybe something like

    x = cell[a1].value
    y=cell[b1].value
    or something?

    "Raman" wrote:

    > You can create a variable in VBA and assign it the value of the cell
    > using the activeccell.value property
    >
    > You can assign value when you track the cell with value
    >
    > Your code could be
    > dim x 'declare a variable
    > x=activecell.value 'assing the variable the value of cell
    >
    > For more,post your questions on
    > http://groups.google.co.in/group/answers-for-everything
    >
    >


  9. #9
    Dave Peterson
    Guest

    Re: How do I assign the value in a cell to a variable?

    Dim Val01 as Variant
    dim Val02 as Variant
    Dim Val03 as Variant
    dim Val04 as Variant
    Dim Val05 as Variant
    dim Val06 as Variant

    with worksheets("whateverthenameishere")
    val01 = .range("a1").value
    val02 = .range("b99").value
    val03 = .range("c23").value
    val04 = .range("d13").value
    val05 = .range("a11").value
    val06 = .range("x9999").value
    end with

    =============
    If you're setting this up and the users can insert/delete rows/columns, you may
    want to use Insert|Name|Define to give each of those cells a nice name. Then if
    they insert or delete rows or columns, the name will "move" with that cell--as
    long as the user doesn't delete that cell.


    with worksheets("whateverthenameishere")
    val01 = .range("name01").value
    val02 = .range("name02").value
    val03 = .range("name03").value
    val04 = .range("name04").value
    val05 = .range("anothernamehere").value
    val06 = .range("useanicenamehere").value
    end with

    I dimmed all the variables as variants, since I don't know if you have strings
    or numbers in them.

    Rookie_User wrote:
    >
    > That works if you know or have the active cell what you want. But lets say
    > you have six variables and you know of six different cells that have
    > information you want. Can you assign the values of those into the different
    > variables..
    >
    > maybe something like
    >
    > x = cell[a1].value
    > y=cell[b1].value
    > or something?
    >
    > "Raman" wrote:
    >
    > > You can create a variable in VBA and assign it the value of the cell
    > > using the activeccell.value property
    > >
    > > You can assign value when you track the cell with value
    > >
    > > Your code could be
    > > dim x 'declare a variable
    > > x=activecell.value 'assing the variable the value of cell
    > >
    > > For more,post your questions on
    > > http://groups.google.co.in/group/answers-for-everything
    > >
    > >


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1