+ Reply to Thread
Results 1 to 7 of 7

Get cell value and use as vba variable

  1. #1
    Registered User
    Join Date
    08-02-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    Get cell value and use as vba variable

    Hi,

    I am trying to find a way where I can use a worksheet cell value in vba code. ie.. I have vba code
    Please Login or Register  to view this content.
    Sometimes these values will change and I would like to just change them in a cell in a worksheet and have the code updated from the cell values. is this possible please.

    Regards
    David

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Get cell value and use as vba variable

    Hi David,

    Try this where the range is in cell A2 (change to suit):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,671

    Re: Get cell value and use as vba variable

    deleted....
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    08-02-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Get cell value and use as vba variable

    Hi Robert,

    Thanks for your reply,

    I seem to have the values I want now in the variables but copying those values in the worksheet don't seem to work well. ie.. if I use
    Please Login or Register  to view this content.
    this will copy 2 different sections ie.. copies from B4 to B572 without the middle rows B202 to B435. if is use the strMyRange it copies all from B4 to B572?

  5. #5
    Forum Contributor
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    365
    Posts
    199

    Re: Get cell value and use as vba variable

    What excactly are you trying to achieve? Why do you need the values in a variable?

    You can also store the range itself in a range variable.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,671

    Re: Get cell value and use as vba variable

    Cell Z1 --> B4:B201, B436:B572

    Range(range("Z1").value).Copy Dest

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Get cell value and use as vba variable

    worksheet don't seem to work well
    That's odd as it worked for me

    If the non adjacent range is entered correctly (as protonLeah has done) into the cell your code references it should work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 06-18-2015, 09:10 AM
  2. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  3. Replies: 4
    Last Post: 05-07-2014, 03:08 AM
  4. [SOLVED] Assigning A Cell Address to A Variable, Using A Variable - Error '1003'
    By ch_abs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2014, 01:36 PM
  5. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  6. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  7. Replies: 2
    Last Post: 07-24-2012, 11:47 AM

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