Getting a range of data when rows are blank

Skippy

Board Regular
Joined
Mar 3, 2002
Messages
194
Can't seem to figure the syntax for this. I want to fill a listbox with all the data from Columns A to D in a worksheet. The following works fine if Columns A and D have the same number of filled rows. But I have, say 200 rows in Column A and only 30 in Column D. How can I get 200 rows of data for Columns A to D (including blanks) when the columsn are of different lenght?
Code:
varData = .Range(.Range("A2"), .Range("D65536").End(xlUp))
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Like this?

Code:
varData = .Range("A2:D" & .Range("A65536").End(xlUp).Row)

where column A contains the largest number of used rows.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
If the exact column that will contain the largest number of rows isn't known in advance then you could use something aqlong the lines of:

Code:
Sub test()

Dim myarray(1 To 4) As Long, i As Integer, vardata As Variant

For i = 1 To UBound(myarray)
    myarray(i) = Cells(65536, i).End(xlUp).Row
Next i
With Sheets("sheet1")
vardata = .Range(.Range("A2"), .Range("D" & Application.WorksheetFunction.Max(myarray)))
End With


End Sub

Regards

Richard[/i]
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,996
Messages
5,834,785
Members
430,322
Latest member
excelnoobnoob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top