+ Reply to Thread
Results 1 to 7 of 7

Dynamic range

  1. #1
    Registered User
    Join Date
    02-26-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    14

    Dynamic range

    Hi

    How can I define a dynamic range that will depend on the cell value of another sheet?

    I want VBA to loop into the first sheet and identify the value of the first cell. Then go to the second sheet, identify all the cells that have the same value and define these cells as the range (cells with similar value are adjacent). Thanks

    This is the section I need to change:

    Please Login or Register  to view this content.
    Here is the full script:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Dynamic range

    ProtoVB,

    This code will get the ranges defined, but what do you want to do with the ranges once they are defined?
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    02-26-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dynamic range

    Hi tigeravatar and thank you for your post.

    Once I have identified the range I want to sum the values in this range and past the value into another sheet.
    I will take a close look at your module and say if it does what I want, if I can adapt it or if I am looking for something different

  4. #4
    Registered User
    Join Date
    02-26-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dynamic range

    Your script does the job but given my limited understanding of VBA and the complexity of your code I am struggling to adapt the last part, basically calling a function that will sum the value of all the cells in the various offseted ranges and import the data into the Summary sheet.

    The problem lies in calling the function (Compile error: ByRef argument type mismatch)

    Hi have highlighted the modifications I have done in your script and I have attached the excel file I am working on.

    Here is the module with the code

    Please Login or Register  to view this content.

    Module with the function:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Dynamic range

    ProtoVB,

    There's no reason to call a separate function just to sum, this should work for you:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-26-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dynamic range

    Works perfectly, thanks a lot!

  7. #7
    Registered User
    Join Date
    02-26-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dynamic range

    Here is a way to run the script by calling functions:

    Public variables:

    Please Login or Register  to view this content.
    The module:

    Please Login or Register  to view this content.
    The function:

    Please Login or Register  to view this content.

+ 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