ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro for selecting non-adjacent cells (https://www.excelbanter.com/excel-discussion-misc-queries/171808-macro-selecting-non-adjacent-cells.html)

EricBB

macro for selecting non-adjacent cells
 
how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.

CmK

macro for selecting non-adjacent cells
 
Range("A" & ActiveCell.Row & ",C" & ActiveCell.Row & ",E" & ActiveCell.Row &
",H" & ActiveCell.Row & ",K" & ActiveCell.Row).SELECT

"EricBB" wrote:

how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.


Dave Peterson

macro for selecting non-adjacent cells
 
I'd use:

Dim iRow As Long
Dim myRng As Range

iRow = 5 'or activecell.row
With ActiveSheet
Set myRng = Intersect(.Rows(iRow), .Range("a1,c1,e1,h1,k1").EntireColumn)
End With
myRng.Select


EricBB wrote:

how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.


--

Dave Peterson

Ron de Bruin

macro for selecting non-adjacent cells
 
Use this for the row where the activecell is

Cells(ActiveCell.Row, 1).Range("A1,C1,E1,H1,K1").Select



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"EricBB" wrote in message ...
how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.


CmK

macro for selecting non-adjacent cells
 
Obvioucly i am new to this just curious how can you refer to a range object
from a cells method
Isnt range higher in the object hierachy

Thanks in advance


"Ron de Bruin" wrote:

Use this for the row where the activecell is

Cells(ActiveCell.Row, 1).Range("A1,C1,E1,H1,K1").Select



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"EricBB" wrote in message ...
how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.



EricBB

macro for selecting non-adjacent cells
 
thanks a lot CMK, Dave, Ron.

"EricBB" wrote:

how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.


Ron de Bruin

macro for selecting non-adjacent cells
 
Hi CmK

It is an unusual way of using range I agree.
I believe I saw Tom O posted it first a few years ago.
When you enter for example €śCells€ť you will see that range is in the Intellisense
Dropdown after you press the. (Dot after cells)

And you see that it is working OK

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"CmK" wrote in message ...
Obvioucly i am new to this just curious how can you refer to a range object
from a cells method
Isnt range higher in the object hierachy

Thanks in advance


"Ron de Bruin" wrote:

Use this for the row where the activecell is

Cells(ActiveCell.Row, 1).Range("A1,C1,E1,H1,K1").Select



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"EricBB" wrote in message ...
how can i edit the below line so that row no. will be a variable. i.e. if i
select cell "A5" the "3" will become 5.

Range("A3,C3,E3,H3,K3").Select

thanks for any help.





All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com