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
.