Excel formula

Closed
Swim176 - Nov 10, 2015 at 05:35 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Nov 10, 2015 at 11:20 AM
Hello,

How do I put in a formula to search a worksheet and add the numbers up which is in the cell next to a name.

Ie. I want to search for DS across a worksheet.
In the worksheet it will have DS in a cell then 6 in cell next.
I want to add up all occurrences where this happens.

How can I do it thanks.

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Nov 10, 2015 at 11:20 AM
Hi Swim,

Give the following code a try:
Sub RunMe()
Dim mValue As Long
Dim sValue As String

sValue = InputBox("Please input your search value:")

Set c = Cells.Find("DS")
If Not c Is Nothing Then
    firstAddress = c.Address
    Do
        mValue = mValue + c.Offset(0, 1)
        Set c = Cells.FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
End If

MsgBox "All cells added up to the right of " & "'" & sValue & "'" & " results in: " & mValue

End Sub


Best regards,
Trowa
0