+ Reply to Thread
Results 1 to 20 of 20

Adding specific Rows and columns to an array

  1. #1
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Adding specific Rows and columns to an array

    Hi all,

    Im learning some VBA to achieve a task i have so i may be asking multiple questions as i go, but first.

    If i have a datasheet with rows and columns, some rows have SA and some rows have SI in column B, i want the data from 7 or 9 dependant on the value in column B and 11 irrespective.

    What i have currently is as follows.

    Please Login or Register  to view this content.
    Im getting an error about syntax when i do this.

    To ensure the correct data is being copied im also trying to print those respective arrays to other sheets.

    Please Login or Register  to view this content.
    This is all under a button and looks like this.

    Please Login or Register  to view this content.
    Any assistance is much appreciated.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Hi Fluff,

    I tried that but i got a "Run-time error '5':"
    Invalid procedure call or argument.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    What line gave that error?

  5. #5
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    This one did

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    Ok,
    Do you have data in col A?
    Does col B have "SA" as the entire contents of a cell?

  7. #7
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    There is a gap on the second row? and headers in the top row? sorry.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    OK, in that case change the line beginning Ary= to
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Okay cool, so it works but it only returns the top 2 results.

    Is this because the code.

    Please Login or Register  to view this content.
    Is set to "To 2" ? If so, how can i tell it to perform this function for all rows currently with data in sheet1?

    P.S. thanks btw

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    It should work for all the values, can you upload a workbook?

  11. #11
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Yes mate, here you go.

    Sorry this is being such a pita.

    This is just the first step of many, once they are arrayed correctly I need to figure out how to perform the validations against the values!
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    My mistake the last line should be
    Please Login or Register  to view this content.
    I've also added the Si array to go into cols D:E

  13. #13
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    That works wonderfully thanks.

    Now what i need to figure out is how to check the values within the arrays against one another.

    So now that we have the correct values in SA and SI i need to see which values in SI match a value in SA and then return the total of those values that match in SI and return a field accordingly.

    Array Sales Headers (2 = SA) ,9,11
    Array Sales Invoices (2 = SI) ,7,11

    For Sales Header 9, Search Sales Invoices 7 = 9 (11) Return Mini Invoice Array 7,11 (Where 9=7)

    IF total of 11 in Mini Invoice Array = relative Sales Header array 9,11. = MATCH
    IF Total of 11 in mini invoice array > relative sales header array 9,11. = GREATER VALUE
    IF Total of 11 in mini invoice array < relative sales header array 9,11. = LESSER VALUE
    If no row in Sales invoice matches row in sales header = NO INVOICE

    Got any suggestions?

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    Are you only interested in the numerical values?

  15. #15
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Yes, basically the SA array can have multiple SI or singular SI rows that add up to the same as one of the SA rows.

    Its reconciliation quite simply. I want to make the rows that match and flag errors for those that dont.

  16. #16
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    Is this of any use
    Please Login or Register  to view this content.
    It shows the value of SA-SI & the unaccounted invoices

  17. #17
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Hey mate,

    That is pretty cool, though some of the data is a bit strange.

    One result returned "-5.6843418860808E-14" as a value.

    This actually works quite well in all other respects.

    Im remiss to ask more of you, but would you mind kindly explaining how your code works so that i can better understand how its actually implemented?

    As in a line by line explanation of the purpose of the code, you dont have to explain all the function parameters or whatever because i can look that stuff up. More the way that you've constructed it to work.

  18. #18
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    Please Login or Register  to view this content.
    HTH

  19. #19
    Registered User
    Join Date
    06-01-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    26

    Re: Adding specific Rows and columns to an array

    Thanks man, that explains a lot.

  20. #20
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,097

    Re: Adding specific Rows and columns to an array

    You're welcome

+ 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: 8
    Last Post: 09-20-2017, 02:09 AM
  2. [SOLVED] macro to copy specific columns and rows for a specific month and week
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2015, 11:23 AM
  3. Array Adding Rows
    By JayReina in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-21-2013, 09:26 AM
  4. [SOLVED] Adding Record to data table + preserve array formulas in specific columns
    By olivierpbeland in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 02:33 PM
  5. [SOLVED] Macro code to Copy specific rows into specific columns
    By macrofan2012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2012, 11:24 AM
  6. Replies: 4
    Last Post: 06-28-2012, 07:08 AM
  7. Replies: 1
    Last Post: 05-18-2010, 05:50 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