ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select specific cells in same row as active cell (https://www.excelbanter.com/excel-programming/381926-select-specific-cells-same-row-active-cell.html)

michaelberrier

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


Gary''s Student

Select specific cells in same row as active cell
 
After you have got the ActiveCell:

Dim RW As Long
RW = ActiveCell.Row
Range(Cells(RW, "A"), Cells(RW, "J")).Select

--
Gary's Student
gsnu200702


"michaelberrier" wrote:

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




All times are GMT +1. The time now is 10:16 PM.

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