Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 50
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
CmK CmK is offline
external usenet poster
 
Posts: 69
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.misc
CmK CmK is offline
external usenet poster
 
Posts: 69
Default 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.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 50
Default 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.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard Navigation - selecting non-adjacent rows Katie Excel Discussion (Misc queries) 8 November 6th 07 06:20 PM
Selecting all cells using macro robertlewis Excel Discussion (Misc queries) 3 October 11th 06 10:13 PM
By selecting cells adjacent to cells tally sheet tom Excel Worksheet Functions 2 September 20th 06 07:09 PM
selecting adjacent cells wfcmark New Users to Excel 4 December 2nd 05 09:23 AM
selecting non adjacent cells fran Excel Worksheet Functions 4 April 25th 05 12:54 AM


All times are GMT +1. The time now is 08:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"