Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Select cells from a variable position

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Select cells from a variable position

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Select cells from a variable position

Thanks for your input... but what if I need to select two separate ranges at
the same time.... Resize only pick up a continuous range.

For instance I need to select cells on col A,B,F,G,J on a specific row

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Select cells from a variable position

Use Application.Union to combine several cells into a single Range
object:


Dim RR As Range
Dim RowNum As Long
RowNum = ActiveCell.Row
Set RR = Application.Union( _
Cells(RowNum, "A"), Cells(RowNum, "C"), Cells(RowNum, "E"))
RR.Select

Of course, all the cells must be on the same worksheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sat, 12 Sep 2009 19:26:01 -0700, Alberto Ast
wrote:

Thanks for your input... but what if I need to select two separate ranges at
the same time.... Resize only pick up a continuous range.

For instance I need to select cells on col A,B,F,G,J on a specific row

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Select cells from a variable position

It works thanks

"Chip Pearson" wrote:

Use Application.Union to combine several cells into a single Range
object:


Dim RR As Range
Dim RowNum As Long
RowNum = ActiveCell.Row
Set RR = Application.Union( _
Cells(RowNum, "A"), Cells(RowNum, "C"), Cells(RowNum, "E"))
RR.Select

Of course, all the cells must be on the same worksheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sat, 12 Sep 2009 19:26:01 -0700, Alberto Ast
wrote:

Thanks for your input... but what if I need to select two separate ranges at
the same time.... Resize only pick up a continuous range.

For instance I need to select cells on col A,B,F,G,J on a specific row

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Select cells from a variable position

One more question... this is what I wrote

RowNum = ActiveCell.Row
Set RR = Application.Union(Cells(RowNum, "A"), Cells(RowNum, "B"), _
Cells(RowNum, "D"), Cells(RowNum, "E"), Cells(RowNum, "F"), _
Cells(RowNum, "G"), Cells(RowNum, "I"), Cells(RowNum, "J"))
RR.ClearContents

But as you can see there are several consecutive cells... is there a way to
simplify the comand?

Thanks

"Chip Pearson" wrote:

Use Application.Union to combine several cells into a single Range
object:


Dim RR As Range
Dim RowNum As Long
RowNum = ActiveCell.Row
Set RR = Application.Union( _
Cells(RowNum, "A"), Cells(RowNum, "C"), Cells(RowNum, "E"))
RR.Select

Of course, all the cells must be on the same worksheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sat, 12 Sep 2009 19:26:01 -0700, Alberto Ast
wrote:

Thanks for your input... but what if I need to select two separate ranges at
the same time.... Resize only pick up a continuous range.

For instance I need to select cells on col A,B,F,G,J on a specific row

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Select cells from a variable position

This single line of code should do what your post code does...

Intersect(ActiveCell.EntireRow, Range("A:B,D:G,I:J")).ClearContents

--
Rick (MVP - Excel)


"Alberto Ast" wrote in message
...
One more question... this is what I wrote

RowNum = ActiveCell.Row
Set RR = Application.Union(Cells(RowNum, "A"), Cells(RowNum, "B"), _
Cells(RowNum, "D"), Cells(RowNum, "E"), Cells(RowNum, "F"), _
Cells(RowNum, "G"), Cells(RowNum, "I"), Cells(RowNum, "J"))
RR.ClearContents

But as you can see there are several consecutive cells... is there a way
to
simplify the comand?

Thanks

"Chip Pearson" wrote:

Use Application.Union to combine several cells into a single Range
object:


Dim RR As Range
Dim RowNum As Long
RowNum = ActiveCell.Row
Set RR = Application.Union( _
Cells(RowNum, "A"), Cells(RowNum, "C"), Cells(RowNum, "E"))
RR.Select

Of course, all the cells must be on the same worksheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sat, 12 Sep 2009 19:26:01 -0700, Alberto Ast
wrote:

Thanks for your input... but what if I need to select two separate
ranges at
the same time.... Resize only pick up a continuous range.

For instance I need to select cells on col A,B,F,G,J on a specific row

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work
on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus
cell thee
spots to the right... my current cell location might vary.
Thanks,




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default Select cells from a variable position

Thanks.. Your last comment plus Chip input mae my solution.

"Gord Dibben" wrote:

ActiveCell.Resize(1, 5).Select

Note: most times there is no need to select a range in order to work on it.

ActiveCell.Resize(1, 5).Interior.ColorIndex = 3


Gord Dibben MS Excel MVP


On Sat, 12 Sep 2009 17:50:01 -0700, Alberto Ast
wrote:

If I am in any cells how do I select same cell plus right cell plus cell thee
spots to the right... my current cell location might vary.
Thanks,



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
select the range with the cell's position is a variable. [email protected] Excel Programming 2 March 14th 08 02:46 AM
Can I make array position A(12) into a variable A(12*n) ? Paul Excel Worksheet Functions 1 October 9th 06 10:37 PM
Select player from list and get his position in next column Massivemike Excel Discussion (Misc queries) 2 September 10th 05 12:56 PM
Select a string without knowing position Who I Am Excel Programming 1 September 5th 05 04:35 AM
Range.Select with variable cells ? [email protected] Excel Programming 2 October 29th 03 08:43 PM


All times are GMT +1. The time now is 09:50 PM.

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

About Us

"It's about Microsoft Excel"