+ Reply to Thread
Results 1 to 9 of 9

How do i reference a dynamic cell range in VBA code

  1. #1
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Question How do i reference a dynamic cell range in VBA code

    I am trying to find a way to reference cells in a table using VBA code, when the position of the cells changes with every row inserted in data above it. I have attached a sample of my what I am working with, my code is in ThisWorkbook

    Forum Help Sheet.xlsm

    Any suggestions are appreciated!!!

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: How do i reference a dynamic cell range in VBA code

    Hi,

    do you mean the row of "ABC" in column 1 and "DEF" in column 4?

    Please check the code in the attached file where "ABC" is searched in column 1 and then the value next to it is compared:
    # Forum Help Sheet.xlsm #
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How do i reference a dynamic cell range in VBA code

    Yes, I that table is going to be filled with variable like ABC and DEF and I need to reference the cell adjacent to each one.

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: How do i reference a dynamic cell range in VBA code

    Hi,

    did you check the code in the attachment of post #2? Does it work for you?

  5. #5
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How do i reference a dynamic cell range in VBA code

    I haven't had a chance to..but i will and let you know. Thank you so much for the help!!

  6. #6
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How do i reference a dynamic cell range in VBA code

    Yes! It works! Thank you!! Do i just write the same code for every item I'm going to have in my table?

  7. #7
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: How do i reference a dynamic cell range in VBA code

    The best would be to take the values to search for from the sheet itself (e.g. the values to use are in column X), but with the information you gave in previous posts I cannot see a structure in the worksheet.
    Using such code with fixed strings like "ABC" and "DEF" is not flexible as I assume you don't want to adapt the code whenever there is a new string to search for.

    So, if possible, could you explain the worksheet and how it should work with the data more precisely?

  8. #8
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How do i reference a dynamic cell range in VBA code

    Ill try and post a bigger sample so you can see what i am trying to do...i used the code you created on all the variables and something went wrong...and i cant figure out what it is

  9. #9
    Registered User
    Join Date
    10-03-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How do i reference a dynamic cell range in VBA code

    SAMPLE.xlsm Here is a bigger sample of what I am trying to accomplish. Again, I really appreciate your time and help.
    Last edited by alice03; 10-08-2013 at 10:59 AM.

+ 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. [SOLVED] How to reference a cell within a dynamic range
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2013, 05:45 PM
  2. VBA Dynamic Range - An Indirect Cell Reference
    By ExcelHelp2013 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2013, 11:08 AM
  3. Replies: 6
    Last Post: 03-05-2012, 04:46 PM
  4. [SOLVED] Dynamic Range Reference, Varying Size of Range
    By cdiaz in forum Excel General
    Replies: 2
    Last Post: 06-30-2011, 02:49 PM
  5. using a dynamic reference cell to copy a range of cells within a data table
    By mcash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2010, 10:22 AM

Tags for this Thread

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