Consulting

Results 1 to 5 of 5

Thread: Solved: Search for cell values then sum scell to......

  1. #1

    Solved: Search for cell values then sum scell to......

    VBA newbie here

    I want to search for specifc cell values, then sum the values to the left of each value found. Example - "excess" finds N9, H15 , J22; now I want the sum of all (left) cell values : M9, G15, I22, etc

    Thanks

    Fiz

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Welcome to VBAX

    [VBA]Option Explicit
    Sub FindExcess()
    Dim Total As Long
    Dim c As Range
    Dim FirstAddress As String
    Dim ToFind As String

    ToFind = InputBox("Text to find", "Custom Search", "excess")
    With ActiveSheet.Cells
    Set c = .Find(ToFind, LookIn:=xlValues)
    If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
    Total = Total + c.Offset(, -1)
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
    End If
    End With
    MsgBox Total
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You could try an array formula, such as

    =SUM(IF(B1:N19="abc",A1:M19))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks-a-million!!

  5. #5
    Awesome!! Thanks-a-million!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •