Multiple Range Select

Lamar in Houston

Board Regular
Joined
Jan 21, 2006
Messages
72
I have a worksheet which contains varying rows of data from day to day. I need to automate a way for a user to collect the data from all cells in two non-contigous columns, those being B and Y, from row 3 to the last record in those columns.

Below is the track I am on, one that I cannot make work with columns that are non adjacent.

Range (("B3:" & Range("B65536").End(xlUp).Address)), _
(("Y3:" & Range("Y65536").End(xlUp).Address))


Any suggestions?

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What is it that you wish to do? Perhaps?
Code:
set rngMyVar = union(Range (("B3:B" & Range("B65536").End(xlUp).row)), _
(("Y3:Y" & Range("Y65536").End(xlUp).row))
 
Upvote 0
or
Code:
Range ("B3:b" & Range("B65536").End(xlUp).row & ",Y3:y" & _
     Range("Y65536").End(xlUp).row)
 
Upvote 0
Oh, and really, you should do it like so:
Code:
set rngWhatever = range("A1:A" & range("A" & rows.count).end(xlup).row)
in order to make your code robust going forward. The versions after Excel 2003 will have 2<sup>20</sup> rows instead of 2<sup>16</sup>.
 
Upvote 0
I am trying to copy the two columns of data. The selected cells will be pasted to another workbook which the user will have open. Note that said workbook will have a different name from day to day.

Your macro works fine on the selection but when I add a Copy statement I get the error "That command cannot be used on multiple selections". This is puzzling since I can do it on the keyboard via the Ctrl key.

Any insights?

Thanks
 
Upvote 0
Your macro works fine on the selection but when I add a Copy statement I get the error "That command cannot be used on multiple selections". This is puzzling since I can do it on the keyboard via the Ctrl key.
Any insights?
Thanks
You should not be able to do it interactively either (the copy that is). This would be because the size of the areas in the two columns have a differing number of rows. Try it manually. You cannot select A1:A3 and C1:C2 and copy and paste because you have differening numbers of rows. But you can select A1:A3 and C1:C3 and copy and paste, no problem.
 
Upvote 0
Did you want to do like this ?
Code:
With Range ("B3", Range("B" & Rows.Count).End(xlUp))
    Range(.Address & "," & .Offset(, 23).Address).Copy
End With
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,460
Members
448,965
Latest member
grijken

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