Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Select specific cells in same row as active cell

I need the code for selecting a specific range of cells on the same row
as the active cell. The active cell will be selected with a cell.find
operation, so it will not always be in the same column. Thus, an
activecell.offset won't work.

I tried putting the range in the code, but it failed. Here is how the
code looks now:

Sub Look_Here()
Dim WhatFor
WhatFor = ActiveSheet.Cells(4, 1)

Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext,
searchorder:=xlByRows, MatchCase:=False).Activate
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 8)).Select <---IT
IS HERE THAT I WANT TO REFER TO CELLS A:J ON THE SAME ROW AS THE
ACTIVE(found) CELL.

thanks to all

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Select specific cells in same row as active cell

Try this

Range(Cells(ActiveCell.Row, "A"), Cells(ActiveCell.Row, "J")).Select


--

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


"michaelberrier" wrote in message ups.com...
I need the code for selecting a specific range of cells on the same row
as the active cell. The active cell will be selected with a cell.find
operation, so it will not always be in the same column. Thus, an
activecell.offset won't work.

I tried putting the range in the code, but it failed. Here is how the
code looks now:

Sub Look_Here()
Dim WhatFor
WhatFor = ActiveSheet.Cells(4, 1)

Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext,
searchorder:=xlByRows, MatchCase:=False).Activate
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 8)).Select <---IT
IS HERE THAT I WANT TO REFER TO CELLS A:J ON THE SAME ROW AS THE
ACTIVE(found) CELL.

thanks to all

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Select specific cells in same row as active cell

Oops, wrong code.

Try this

Dim rng As Range
WhatFor = ActiveSheet.Cells(4, 1)
Set rng = Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext, _
searchorder:=xlByRows, MatchCase:=False)
If Not rng Is Nothing Then
Range(Cells(rng.Row, "A"), Cells(rng.Row, "J")).Select
End If



--

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


"Ron de Bruin" wrote in message ...
Try this

Range(Cells(ActiveCell.Row, "A"), Cells(ActiveCell.Row, "J")).Select


--

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


"michaelberrier" wrote in message ups.com...
I need the code for selecting a specific range of cells on the same row
as the active cell. The active cell will be selected with a cell.find
operation, so it will not always be in the same column. Thus, an
activecell.offset won't work.

I tried putting the range in the code, but it failed. Here is how the
code looks now:

Sub Look_Here()
Dim WhatFor
WhatFor = ActiveSheet.Cells(4, 1)

Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext,
searchorder:=xlByRows, MatchCase:=False).Activate
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 8)).Select <---IT
IS HERE THAT I WANT TO REFER TO CELLS A:J ON THE SAME ROW AS THE
ACTIVE(found) CELL.

thanks to all

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Select specific cells in same row as active cell

Perfect sir, thank you.

On Jan 25, 1:06 pm, "Ron de Bruin" wrote:
Try this

Range(Cells(ActiveCell.Row, "A"), Cells(ActiveCell.Row, "J")).Select

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm

"michaelberrier" wrote in oglegroups.com...
I need the code for selecting a specific range of cells on the same row
as the active cell. The active cell will be selected with a cell.find
operation, so it will not always be in the same column. Thus, an
activecell.offset won't work.


I tried putting the range in the code, but it failed. Here is how the
code looks now:


Sub Look_Here()
Dim WhatFor
WhatFor = ActiveSheet.Cells(4, 1)


Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext,
searchorder:=xlByRows, MatchCase:=False).Activate
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 8)).Select <---IT
IS HERE THAT I WANT TO REFER TO CELLS A:J ON THE SAME ROW AS THE
ACTIVE(found) CELL.


thanks to all


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Select specific cells in same row as active cell

Ron,
The shorter code worked just fine. It was easy to adapt to my real
purpose, which was highliting the whole range with each selection.

Thanks again to both of you.
On Jan 25, 1:13 pm, "Ron de Bruin" wrote:
Oops, wrong code.

Try this

Dim rng As Range
WhatFor = ActiveSheet.Cells(4, 1)
Set rng = Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext, _
searchorder:=xlByRows, MatchCase:=False)
If Not rng Is Nothing Then
Range(Cells(rng.Row, "A"), Cells(rng.Row, "J")).Select
End If

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm

"Ron de Bruin" wrote in l...

Try this


Range(Cells(ActiveCell.Row, "A"), Cells(ActiveCell.Row, "J")).Select


--


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


"michaelberrier" wrote in oglegroups.com...
I need the code for selecting a specific range of cells on the same row
as the active cell. The active cell will be selected with a cell.find
operation, so it will not always be in the same column. Thus, an
activecell.offset won't work.


I tried putting the range in the code, but it failed. Here is how the
code looks now:


Sub Look_Here()
Dim WhatFor
WhatFor = ActiveSheet.Cells(4, 1)


Cells.Find(What:=WhatFor, after:=ActiveCell, SearchDirection:=xlNext,
searchorder:=xlByRows, MatchCase:=False).Activate
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 8)).Select <---IT
IS HERE THAT I WANT TO REFER TO CELLS A:J ON THE SAME ROW AS THE
ACTIVE(found) CELL.


thanks to all


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
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
Select Active Cells Umbu Excel Worksheet Functions 0 June 24th 08 02:03 PM
how to select row according active cell? frankosun Excel Programming 2 December 14th 05 09:55 AM
how do I select cells in column A thru F in the active row? jonco Excel Programming 4 August 23rd 05 02:45 AM
Select column cells to the left/right of active selection - an example [email protected] Excel Programming 1 March 24th 05 06:36 PM


All times are GMT +1. The time now is 06:27 AM.

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"