+ Reply to Thread
Results 1 to 14 of 14

Ranges in selection and arrays

  1. #1
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Ranges in selection and arrays

    Hi everyone,

    I have this following code i need help with

    Please Login or Register  to view this content.
    The code is unfinished because i don't know how to convert the first range selection (ex: A to E would be 1 to 5) and store it for later use. I would also want to store the cell range(i, j) of the second selection in another array.

    Here's the code i will use with the arrays

    Please Login or Register  to view this content.
    Thanks in advance.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    What do you need help with? What are you trying to achieve?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    Let me see if i can make this a bit clear.

    I'm trying to store a user selection of ranges and cells into arrays so i can process those selections through the calculations i've already made.

    Suppose user wants to anaylse 3 columns and he selects the range for the first table and the cell of that first table, the macro will store the value of the row to start in and the cell values. I need help making this to happen.

    With that values stored the analyses will take place (the second macro i've made), the problem is i've based the second script on fixed cell values so i want to take the values from the array and use them.

    I've attached an example of the worksheet. In this example if user selects K5, Z5 and AO5 i want the second macro to run K5 against Z5 and K5 against AO5.

    I hope i've made my point a bit clear.

    13081715551.xlsx

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    I'm still not exactly sure but you can try to refer to a user selected range value (a cell is a range) by:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    Here's what i wrote so far.

    Please Login or Register  to view this content.
    The problem is i get the subscript out of range error when i try to store the cell row and columns in cArray().

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    Step through it with F8. Does it fail on the first loop or second?

    ReDim rArray(0) means you'll only be able to apply 1 row variable to his array. Its lower and upper bounds are the same. Its essentially the same as being a singular variable and not an array.

  7. #7
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    It fails on the first loop in this step

    Please Login or Register  to view this content.
    I've also deleted ReDim rArray(0)

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    You still have to dimension the array. It looks like you need a two dimension array. How many row/column numbers are you trying to store in your array?

  9. #9
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    The first array i've set (rArray - one dimension) will be used just to store the row number of the selected range and the second array (cArray - this one is the 2 dimension) will be used to store the row and column number of the cell range. The numbers of rows/columns to store will be based of number inputed by the user, if it's 3 the array will be 2x3.
    Last edited by fgq; 08-18-2013 at 10:07 PM.

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    Then try:
    Please Login or Register  to view this content.
    You'll still have to Dim rArry() with the count of row numbers you'd like to hold there.

  11. #11
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    Thank you, so based on that i've set

    Please Login or Register  to view this content.
    Now the rArray is storing the values correctly the problem is the cArray

    Please Login or Register  to view this content.

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    Try:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-28-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Ranges in selection and arrays

    I couldn't make it work with that commands but i managed to get a workaround.

    If you could help me with my other problem anaylising multiple cells at the same time, i would be appreciated.

    Here's what i mean from the code i have.

    Please Login or Register  to view this content.
    Variable a and d will be the fixed from the first selected cell.
    Variable b and c will have values from the other selected cells which i want to compare against a and d.
    If you have 3 selected cells the comparision i want is cell 1 vs cell 2 and cell 1 vs cell 3 all at the same time so that the line that will be inserted will be equally distribuited.

    Thanks for your patience.

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Ranges in selection and arrays

    So other members and guests can benefit from the thread, please start a new thread with an appropriate title for the new question.

+ 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 use Arrays instead of Ranges
    By Sachy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-10-2013, 10:54 AM
  2. Last Cell Selection using Arrays Part-2
    By plasma33 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2012, 08:29 AM
  3. [SOLVED] Last Cell Selection using Arrays
    By plasma33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2012, 06:16 AM
  4. arrays and ranges
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2012, 12:18 PM
  5. Ranges and Arrays
    By Will Brown in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2005, 12:07 PM

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