Selecting blocks of data with VBA end.xldown and end.xltoright

mudshark

New Member
Joined
Oct 2, 2013
Messages
6
XX_ID_A

Site
Name
Manager
1
Fred
9
1
Mary
1
Jack
9
1
Jill
XX_ID_B
System
Plan
Fname
Lname
Man
Note
1
TAD
John
Smith
6
Service
1
TAD
Jerry
Jones
6
HR
1
TAC
Alan
Berry
7
1
TAB
Mary
Dawson
Sales

<tbody>
</tbody>

Hi
I have some VBA that selects blocks of data from one main sheet based on an identifier in column A and
copies these to separate sheets
But the data can be different sized ranges and non-contiguous data in the right-most columns.
(Left-most column is always filled.)
So using the following code doesn't always select all the data.
After selecting the cell below the XX_ID identifier i then try to select the whole block.
Code:
Set ACTrng = Range(Selection, Selection.End(xlDown).End(xlToRight))
Similar issue if I change the order (xlToRight then xlDown)

a simple example would look something like above.

How do i approach this..
thanks in advance...
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I may have stumbled on the answer to my own question ??? ... select in 2 steps....


Code:
    Set TopRowrng = Range(Selection, Selection.End(xlToRight))
    Set ACTrng = Range(TopRowrng, Selection.End(xlDown).End(xlToRight))

Is that a robust method ?
 
Last edited:
Upvote 0
Try this

Code:
Sub test()
  Dim rng As Range
  For Each rng In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
    rng.EntireRow.Copy
  Next
End Sub

With the above you can copy the block.
Where do you want to paste it, on a new sheet or does the sheet already exist?
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,685
Members
449,117
Latest member
Aaagu

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