Viewing 8 posts - 1 through 8 (of 8 total)
  • Excel Question
  • steve-g
    Free Member

    Is there a way I can get excel to vlookup data, pull through the values but only show the negative ones all in one cell. Like having an IF statement looking at the results of the vlookup but all in one formula?

    Cheers

    djglover
    Free Member

    here is what I’d do, on a new / hidden sheet do a nested vlookup this =if(vlookup(a1,a2:b6,2)>0,0,(vlookup(a1,a2:b6,2)), that will pull all the negatives

    then sum the whole range all in a seperate cell

    Stoner
    Free Member

    “only show the negative ones all in one cell”

    explain?

    As a list? “-4, -5, -24, -54”
    or a sum? “-87”

    or what?

    plop_pants
    Free Member

    Sounds like you might need to write a custom vba function to read in the range and loop through each value in the range, append each negative value found into a string variable and return that variable.

    something like

    Function Negatives (ParamArray arglist() as Variant) as String

    Dim cell As Range

    Negatives = “”

    For Each arg In arglist
    For Each cell In arg
    If cell < 0 Then Negatives = Negatives & “,” & cell
    Next Cell
    Next arg

    End Function

    In your spreadsheet use this function like any other:

    =Negatives(A1:A100)

    Should also work with multiple ranges : eg =Negatives(A1:A100,B1:B50)

    plop_pants
    Free Member

    Just tested it and it works fine. I can send it to you if you like?

    steve-g
    Free Member

    I think I’ve done it..

    If vlookup…..<0,vlookup…….,0

    Cheers
    Steve

    plop_pants
    Free Member

    Cleaner version:

    Function Negatives(ParamArray arglist() As Variant) As String

    Dim arg As Variant

    Dim cell As Range

    Negatives = “”

    For Each arg In arglist
    For Each cell In arg
    If cell < 0 Then
    If Negatives = “” Then
    Negatives = cell
    Else
    Negatives = Negatives & “,” & cell
    End If
    End If

    Next cell
    Next arg

    End Function

    woodywoodbine
    Free Member

    exctly what I was thinking steve-g. No need to get into vb unless completely necessary in my opinion!

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Excel Question’ is closed to new replies.