LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Selecting cells in Excel

use the worksheet "Find" method. Bel;ow is an example.
As with a ctr+F, th eFind method continuously loops
through any found cells. To stop this, we simply save the
address of the first cell and loop until we arrive back
there again.
The code below does a find, then if a cell is founf,
records its address then does a DO...LOOP for any other
cells.

Add the following to a standard code module and run
Tester:

Option Explicit
Sub Tester()
MsgBox "Total is : " & FindCells("Total")
End Sub


Function FindCells(sFindWhat As String) As Double
Dim sFirstAddress As String
Dim rFoundCell As Range
Dim dGrandTotal As Double

With ActiveSheet.Cells

Set rFoundCell = .Find(sFindWhat)

If Not rFoundCell Is Nothing Then

sFirstAddress = rFoundCell.Address

Do
dGrandTotal = dGrandTotal + _
rFoundCell.Offset(0, 1).Value
Set rFoundCell = .Find(sFindWhat, rFoundCell)

Loop Until rFoundCell.Address = sFirstAddress

End If

End With
FindCells = dGrandTotal

End Function

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi all,

Can anyone tell me how to select cells in Excel using VB

programming.
I'm trying to get the macro to run a find on the

word "Total".
Then select the data from the cells to the right of it.
Then paste the info in another spot.

Can anyone help please?

Thanx in advance

Salman
.

 
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
Excel keeps selecting two cells eel_electric Excel Discussion (Misc queries) 3 September 10th 08 09:59 PM
When selecting cells in Excel 07 why doesn't it highlight? Andrea Excel Discussion (Misc queries) 1 November 6th 07 02:02 PM
The cursor on my Excel spreadsheet is not selecting cells. auberginewellies Excel Discussion (Misc queries) 2 March 20th 06 06:36 PM
help in selecting cells , VBA in Excel Kortrijker Excel Programming 1 February 19th 04 12:45 PM
Activiating and Selecting Excel Cells in VB.NET Zhichun Pu Excel Programming 1 July 11th 03 01:46 AM


All times are GMT +1. The time now is 09:10 AM.

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"