TotallyConfused
Board Regular
- Joined
- May 4, 2017
- Messages
- 247
- Office Version
- 365
- Platform
- Windows
Hello all you MrExcel experts
I have a sheet with 26 columns and approximately 250,000 rows of data. The number of columns will stay the same, however, the number of rows will increase. I will be comparing data in columns 'B, D, N, Q', and depending of the results of that comparison, some data may or may not be placed in column 'Y' (which will be the fifth element of the array). None of the other columns will be accessed. I think I can do the comparison and the writing of data to that fifth element. To speed up the processing time, I'd like to load these five columns into an array, do the processing there, then write the data back to Excel. I could create an array that holds the whole spreadsheet, but considering the limited number of columns that are involved, that seems like an inefficient way to code, as well as possible memory limitations due to the large amount of data.
I know I could set up a loop where I'd load individual cells, but with 5 columns, each with a quarter million or more rows, that is a lot of loops. Another option I've considered, is to create a dummy sheet, copy the above mentioned columns to it, load it into the array, do the processing and then delete that sheet. Surely there must be a better way. I have two questions.
1 ) I tried splitting the loading process into five parts and load one column at a time. Column 'B' loads fine as the first element of the array (as shown in my sample code). From then on, I'd either overwrite the first element or get various error messages depending on what I tried. I've tried using 'ReDim' and 'ReDim Preserve', but since I'm not sure how to handle those statements, I met with failure. Is it possible to load only these five non-adjacent columns into an array, and if so, how?
2 ) During the processing, only the fifth element of the array, (which is column 'Y') will be changed. This is the only one that needs to be written back to Excel, and it will be placed in its original position, starting at 'Y4'. How do I write this one array element back to column 'Y' of the spreadsheet?
I've tried various versions of the following macro, but this is what I'm looking at now.
THANK YOU in advance for any help or suggestions you may be able to offer.
TotallyConfused
I have a sheet with 26 columns and approximately 250,000 rows of data. The number of columns will stay the same, however, the number of rows will increase. I will be comparing data in columns 'B, D, N, Q', and depending of the results of that comparison, some data may or may not be placed in column 'Y' (which will be the fifth element of the array). None of the other columns will be accessed. I think I can do the comparison and the writing of data to that fifth element. To speed up the processing time, I'd like to load these five columns into an array, do the processing there, then write the data back to Excel. I could create an array that holds the whole spreadsheet, but considering the limited number of columns that are involved, that seems like an inefficient way to code, as well as possible memory limitations due to the large amount of data.
I know I could set up a loop where I'd load individual cells, but with 5 columns, each with a quarter million or more rows, that is a lot of loops. Another option I've considered, is to create a dummy sheet, copy the above mentioned columns to it, load it into the array, do the processing and then delete that sheet. Surely there must be a better way. I have two questions.
1 ) I tried splitting the loading process into five parts and load one column at a time. Column 'B' loads fine as the first element of the array (as shown in my sample code). From then on, I'd either overwrite the first element or get various error messages depending on what I tried. I've tried using 'ReDim' and 'ReDim Preserve', but since I'm not sure how to handle those statements, I met with failure. Is it possible to load only these five non-adjacent columns into an array, and if so, how?
2 ) During the processing, only the fifth element of the array, (which is column 'Y') will be changed. This is the only one that needs to be written back to Excel, and it will be placed in its original position, starting at 'Y4'. How do I write this one array element back to column 'Y' of the spreadsheet?
I've tried various versions of the following macro, but this is what I'm looking at now.
Code:
[COLOR=black][FONT=Calibri]Option Base 1[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]Sub LoadArray()[/FONT][/COLOR]
[COLOR=black][FONT=Calibri] Dim Ary as Variant[/FONT][/COLOR]
[COLOR=black][FONT=Calibri] Dim NumRows as Long[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Sheet1")[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]NumRows = [/FONT][/COLOR][COLOR=black][FONT=Calibri] Range("B"&Rows.Count).End(xlUp).Row[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]Ary = Range("B4:B" & NumRows) ' This loads column 'B' into ARY[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]' Here is where I start picking your brains for some brilliant lines of code.[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]' What do I do now to load columns 'D, N, Q, Y'?[/FONT][/COLOR]
[COLOR=black][FONT=Calibri]End Sub[/FONT][/COLOR]
TotallyConfused