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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Like this?

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

where column A contains the largest number of used rows.
 
Upvote 0
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]
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

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
Back
Top