VBA for selecting Specific Cells Range in Selected Rows

excelakos

Board Regular
Joined
Jan 22, 2014
Messages
79
Hi everyone! I wish you all the best for 2021! I need to do this. In a table range i select multiple cells in different rows. In example i have selected cells in rows 2,3,5,7,10 inside the table range.
Now i want a macro to first recognize the rows (of the table) of the selected cells and in each of the rows to sellect for me specific cell ranges in example in each row i want the first till the 10th column plus the 15th till 20th column
This means i want to be selected in row 2 the 1st till 10th column cell of this row plus the 15th till 20th column cell of this row
Same for all the other rows 3,5,7,10 or whatever the rows would be
 
I was try to understand Fluff's code and your wish, and suppose that you want inversed version.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   
   Dim Rng As Range, Sel As Range, vC
  
   vC = Split(Mid(Target.Address, 2, Len(Target.Address) - 1), "$")
   Set Sel = Cells(1, ActiveCell.Column)
   For Each Rng In Selection.Areas
     Set Sel = Union(Sel, Intersect(Rng.EntireColumn, _
     Range(vC(0) & 1 & ":" & vC(0) & 10 & "," _
         & vC(0) & 15 & ":" & vC(0) & 20)))
   Next Rng
   Sel.Select
  
End Sub
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Case you want to select some column with click in some cell...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
   Dim vC

   vC = Split(Target.Address, "$")(1)
   On Error GoTo EX:
   Range(vC & 1 & ":" & vC & Rows.Count).Select
EX:

End Sub
 
Upvote 0
For col R you can use
VBA Code:
Sub excelakos()
   Dim Rng As Range, Sel As Range
   
   Set Sel = Range("A" & ActiveCell.Row)
   For Each Rng In Selection.Areas
      Set Sel = Union(Sel, Intersect(Rng.EntireRow, Range("R:R")))
   Next Rng
   Sel.Select
End Sub
 
Upvote 0
For col R you can use
VBA Code:
Sub excelakos()
   Dim Rng As Range, Sel As Range
  
   Set Sel = Range("A" & ActiveCell.Row)
   For Each Rng In Selection.Areas
      Set Sel = Union(Sel, Intersect(Rng.EntireRow, Range("R:R")))
   Next Rng
   Sel.Select
End Sub
Thank you once again. It's a pitty i cant apply a 2nd SOLVED...
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,706
Members
449,118
Latest member
MichealRed

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