Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move cursor

Status
Not open for further replies.

Tuff

Instructor
Mar 17, 2003
19
AU
Hi everyone,

How do I get my cursor to move up or down cells in Excel.

I don't want to move to an exact cell reference point. I want it to find a certain value within the spreadsheet, then move either up or down one cell.

Can I do this?
Thanks
 
To move the cursor, use
Code:
Offset

To move the cursor down one, without leaving the column, add 1 to the row and 0 to the column:

Code:
ActiveCell.Offset(1, 0).Select

To move up or to the left, use negative numbers:

Code:
ActiveCell.Offset(-1, -2).Select

moves the cursor one row up and two columns to the left.

All the best,

Carol, Berlin :)
 
And to do the FIND:

fWhat = What you want to find
with sheets("Sheetname").columns(1)'change as required
set fCell = .find(fWhat, lookin:=xlvalues, lookat:=xlwhole)
if not fCell is nothing then
fCell.offset(1,0).select
else
msgbox "Data Not Found"
end if
end with Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Hi Tuff,

Do you actually want to select a cell or are you just interested in knowing that the cell attributes are? Most VB code regarding cells can be written without selecting cells which takes alot more time in execution.

Using Geoff's code...
Code:
fWhat = What you want to find
with sheets("Sheetname").columns(1)'change as required
   set fCell = .find(fWhat, lookin:=xlvalues, lookat:=xlwhole) 
if not fCell is nothing then
   With fCell.offset(1,0)
      TheCellValue = .Value
      TheCellInteriorColorIndex = .Interior.ColorIndex
' .. etc.
'  like adding 1 to the cell value (assuming it's numeric)
      .Value = .Value + 1
   End With
else
   msgbox "Data Not Found"
end if
end with
Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top