Can I range be copied to an array?

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,950
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Obviously with a loop, but is there a better "Excel way" ?

I have
Set cr = .Range("Y" & Index & ":CP" & Index)
But I need to limit this to the last used cell letter before CP.

At the moment I'm doing this
VBA Code:
 x = 96
        Do
            x = x = 1
        Loop Until .Cells(Index, x) = ""
Then I want this in a one-based 1D array.
Or should I just stick to a couple of loops ?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Something like this:

VBA Code:
Set cr = .Range(.Range("Y" & Index), .Range("CQ" & Index).End(xlToLeft))
 
Upvote 0
Solution
Thanks that works great :)
PS I had 2 typos in my Do Loop but don't see how to edit it. But don't needs it now!
 
Upvote 0
Note that that code might cause issues when there are no empty cells in the range in question!
 
Upvote 0
I can't make it fail with or without spaces.
BTW is there a better to get the columns?
Debug.Print Split(cr.Address, "$")(1)
Debug.Print Split(cr.Address, "$")(3)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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