Help! Need to adjust selection code!

TabulaRasa

New Member
Joined
Jul 14, 2015
Messages
10
Hi All,

I need to adjust this bit of code (shown below) to select columns G, AO, and AR not just for the title column (row 7) and a single selected cell's row, but for multiple selected rows.

With ActiveCell
Union(Cells(.Row, "G"), Cells(.Row, "AO"), Cells(.Row, "AR"), Cells(7, "G"), Cells(7, "AO"), Cells(7, "AR")).Select 'select the cells you want

For example, if I had selected a cell in row 37, the code above would select cells 37, G and 37, AO and 37, AR as well as the corresponding cells in row 7.

The problem is that if i were to select multiple cells in multiple rows (say 37, 38, and 40) then it would only return the cells in row 7 and the first of the selected rows (37). What I need is for it to select the cells from row 7, 37, 38, and 40.

I would appreciate any help!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Dim r As Long


r = ActiveCell.Row
Range("G" & r & "," & "AO" & r & "," & "AR" & r).Select

'mutli rows??
 
Upvote 0
Try
Code:
Sub SelectCells()
 Dim r As Long
  r = Selection.Rows.Count
   With ActiveCell
    Union(Cells(.Row, "G").Resize(r), Cells(.Row, "AO").Resize(r), _
     Cells(.Row, "AR").Resize(r), Cells(7, "G"), Cells(7, "AO"), _
      Cells(7, "AR")).Select 'select the cells you want
   End With
End Sub
 
Upvote 0
Dim r As Long


r = ActiveCell.Row
Range("G" & r & "," & "AO" & r & "," & "AR" & r).Select

'mutli rows??

This does not solve the problem that I had presented. I have the code to select in a single row, it is just the multi row part of the puzzle that I am missing.
 
Upvote 0
Try
Code:
Sub SelectCells()
 Dim r As Long
  r = Selection.Rows.Count
   With ActiveCell
    Union(Cells(.Row, "G").Resize(r), Cells(.Row, "AO").Resize(r), _
     Cells(.Row, "AR").Resize(r), Cells(7, "G"), Cells(7, "AO"), _
      Cells(7, "AR")).Select 'select the cells you want
   End With
End Sub

This worked! Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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