Consulting

Results 1 to 3 of 3

Thread: vba to find data in excel

  1. #1

    Exclamation vba to find data in excel

    Hi everybody,
    I am new to the macro. I want to get the output in excel. Can anybody help me in writing macro for that.
    The macro is based on if-else condition.(Count the value based on requirement).
    Please help
    Output
    101/clerk/10000/10=7102/clerk/10000/10=8103/sales,Doctor/20000/20,30=total
    Attached Files Attached Files

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Welcome to VBAX.

    Before working on a macro, have you checked the possibility of using a formula like SUMIFS? If you haven't then it is worth giving consideration.

    I am attaching the file with formula.
    Quote Originally Posted by FORMULA
    =SUMIFS($E$1:$E$10,$A$1:$A$10,$A13,$B$1:$B$10,$B13,$C$1:$C$10,$C13,$D$1:$D$ 10,$D13)
    Attached Files Attached Files
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    For the last one week or so, I am trying desperately to understand the workings of Dictionary Object. It seems to be versatile tool for doing many things and is incredibly faster.

    Here's my attempt at your macro requirement (using dictionary)
    [VBA]Sub CombineData()
    Dim objDic As Object
    Dim sStr As String

    Set objDic = CreateObject("Scripting.Dictionary")
    objDic.Comparemode = vbTextCompare

    For i = 2 To 10
    sStr = Range("A" & i).Value & "/" & Range("B" & i).Value & "/" & Range("C" & i).Value & "/" & _
    Range("D" & i).Value
    If objDic.exists(sStr) Then
    objDic.Item(sStr) = objDic.Item(sStr) + Range("E" & i).Value
    Else
    objDic.Add sStr, Range("E" & i).Value
    End If
    Next i

    With objDic
    Range("G2").Resize(.Count, 2).Value = Application.Transpose(Array(.keys, .items))
    End With

    Set objDic = Nothing

    End Sub[/VBA]

    I am attaching the workbook.
    Attached Files Attached Files
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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