Hi, This is my first post. I've used Excel for a long time but am new to VBA. I have a sheet that has about a million rows and 30 columns of data that is already sorted in a nested fashion based on descending values in three of the the columns. I currently have a macro that goes through each row, selects specific cells from non-contiguous columns (these columns never change), assigns them to a range and then pastes them to another sheet in another workbook. The process continues until the top 25 values based on the third sort criteria are passed to the table. Then the macro skips the remaining rows (because the values in the third sort criteria are out of the top 25) until it gets a new value for the second sort criteria, whereupon it starts a new table for another top 25. The macro works but is very slow because each time it reads a range from one sheet, it then activates the other sheet and pastes a row. So I'd instead of going back and forth between sheets and copying and pasting each row, I'd like to read large blocks from the first sheet into a 2D array first, and then activate the second sheet and paste it all at once. My problem is that I can't figure out how to pass the non-contiguous range to the 2D array. I've seen posts on how to pass an entire row to an array, or how to pass an entire spreadsheet into an array, but not a range that is made up of specific cells from a row. The range will always have the same columns.
So I was hoping someone would pass along some sample code that reads a non-contiguous range into a variable length 2D array using a For Loop. The range is as follows:
Workbooks("test.xlsm").Worksheets("Data").Range("A" & i & ", D" & i & ", F" & i & ", G" & i & ", K" & i & ", L" & i & ", N" & i & ", P" & i & ", Q" & i & ", Y" & i & ", AC" & i).Copy
The loop has different If-Then-Else criteria but I think I can handle that. Thanks.
So I was hoping someone would pass along some sample code that reads a non-contiguous range into a variable length 2D array using a For Loop. The range is as follows:
Workbooks("test.xlsm").Worksheets("Data").Range("A" & i & ", D" & i & ", F" & i & ", G" & i & ", K" & i & ", L" & i & ", N" & i & ", P" & i & ", Q" & i & ", Y" & i & ", AC" & i).Copy
The loop has different If-Then-Else criteria but I think I can handle that. Thanks.