Sub LoadColsIntoArray() ' This code worked perfect with no problem EXCEPT as noted in ' the TEST SECTION at the end. Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2") Dim Ary2 As Variant Dim Ary2rows As Long Dim Cols As String Dim LastRow As Long Application.ScreenUpdating = False With ws2 Cols = "6,20" ' Only load columns 'F' and 'T' into Ary2 array LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious, , , False).Row Ary2 = Application.Index(Cells, Evaluate("ROW(5:" & LastRow & ")"), Split(Cols, ",")) ' Data starts in row #5 End With ' TEST SECTION: ' Okay, now to test whether everything was actually loaded into Ary2 Ary2rows = 1 ' To confirm column 'F' was loaded into array, I added the following three lines. Everything worked perfect. For Ary2rows = 1 To UBound(Ary2, 1) MsgBox "Ary2(Ary2rows, 1) = " & Ary2(Ary2rows, 1) Next ' To confirm column 'T' was loaded into array, I added the following three lines. Encountered a problem. ' The MsgBox displays ONLY 'John10' & 'John9' and nothing else. There were NO error messages. ' It's as if there were ONLY those two names in the column when loaded into Ary2. '--- What is wrong that is causing this problem? --- For Ary2rows = 1 To UBound(Ary2, 2) MsgBox "Ary2(Ary2rows, 2) = " & Ary2(Ary2rows, 2) Next ' Out of curiosity to see what would happen, I added the following three lines. This time, I used the value of ' UBound forAry2 column 1 as the loop counter, but then display values in column #2. ' In this case everything worked perfect with all 6 John's being displayed. This tells me that Column 'T' was ' completely loaded For Ary2rows = 1 To UBound(Ary2, 1) ' NOTE: I'm accessing element #1 of the array, but MsgBox "Ary2(Ary2rows, 2) = " & Ary2(Ary2rows, 2) ' displaying values from element #2 Next ' The following code displays the number 6 as it should MsgBox "Ubound(Ary2,1) = " & UBound(Ary2, 1) ' The following code displays the number '2' for column 'T', but it should be the number '6' MsgBox "Ubound(Ary2,2) = " & UBound(Ary2, 2) Application.ScreenUpdating = True End Sub
THANK YOU in advance for any help you may be able to offer.