VB Selecting non-adjacent range.

I  need some script to select a range of non-adjacent cells based on the current selection.

Here is a sample of the data:

 Sample
In this sample, if the user selects cell A5, A6, A7, or A8 and then runs the script, then the relevant rows would be 5:8 since they all have the same value in Column A. (The data is sorted on column A). Then, within those relevant rows, columns C and D are always selected. So, here, Cells C5:C8 would be selected.
carlosabAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carlosabAuthor Commented:
Sorry. My sample should have ended with "so, here, Cells C5:D8 would be selected."
0
Saqib Husain, SyedEngineerCommented:
Try this code

Sub selectsj()
Dim rw1 As Range
Dim rwl As Range
Set rw1 = ActiveSheet.Range("A:A").Find(Selection.Value)
Set rwl = ActiveSheet.Range("A:A").Find(Selection.Value, , , , , xlPrevious)
Union(ActiveSheet.Range(rw1.Address & ":" & rwl.Address), ActiveSheet.Range(rw1.Address & ":" & rwl.Address).Offset(0, 2).Resize(, 2)).Select
End Sub
0
carlosabAuthor Commented:
Works nice, except that it is also selecting A5:A8. Nothing in A should be selected. Only c5:D8.
0
Saqib Husain, SyedEngineerCommented:
Change

Union(ActiveSheet.Range(rw1.Address & ":" & rwl.Address), ActiveSheet.Range(rw1.Address & ":" & rwl.Address).Offset(0, 2).Resize(, 2)).Select

to

ActiveSheet.Range(rw1.Address & ":" & rwl.Address).Offset(0, 2).Resize(, 2).Select
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carlosabAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.