• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine 3 Macro Codes

Dokat

Member
Hi,

I have 3 sumif and sumifs statements vba codes. They each work but i have to run them separetly. How can i combine all 3 into 1 Macro rather than running them separately. I tried below code but its not returning correct value. Can anyone help? Thanks

Code:
'HDD FORMBRAND LW
Sub SUMIFSLWFORMBRAND()

    Const TOTALSROW = 61
    Dim i, x As Long
   
    With Sheets("HDD")
   
        .Cells(TOTALSROW, 7) = WorksheetFunction.SUMIF(Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW, 5), Sheets("Source").Range("av:av"))

        .Cells(TOTALSROW, 8) = WorksheetFunction.SUMIF(Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW, 5), Sheets("Source").Range("aw:aw"))
               
        For x = 2 To 22
               
        .Cells(TOTALSROW + x, 7) = WorksheetFunction.SUMIFS(Sheets("Source").Range("av:av"), Sheets("Source").Range("CC:CC"), .Cells(TOTALSROW + x, 4), Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW + x, 5), Sheets("Source").Range("CG:CG"), .Cells(TOTALSROW + x, 6))

        .Cells(TOTALSROW + x, 8) = WorksheetFunction.SUMIFS(Sheets("Source").Range("aw:aw"), Sheets("Source").Range("CC:CC"), .Cells(TOTALSROW + x, 4), Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW + x, 5), Sheets("Source").Range("CG:CG"), .Cells(TOTALSROW + x, 6))
       
        For i = 1 To 1
       
        .Cells(TOTALSROW + i, 7) = WorksheetFunction.SUMIFS(Sheets("Source").Range("av:av"), Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW + i, 5), Sheets("Source").Range("CC:CC"), .Cells(TOTALSROW + i, 6))

        .Cells(TOTALSROW + i, 8) = WorksheetFunction.SUMIFS(Sheets("Source").Range("aw:aw"), Sheets("Source").Range("cb:cb"), .Cells(TOTALSROW + i, 5), Sheets("Source").Range("CC:CC"), .Cells(TOTALSROW + i, 6))
   
         
           Next i
        Next x
    End With
End Sub
 
Last edited:
What happens if you put each macro into it's own Sub. Call the 2nd macro from the 1st ... Call the 3rd macro from the 2nd ?
 
Hi ,

Can you post the range references where you want these formulae inserted ?

You have set TOTALSROW to 61 ; does this mean that you want a SUMIF formula inserted in cells F61 and G61 ?

Thereafter , do you want the SUMIFS formulae inserted in cells F62:G93 ?

There seems to be a difference between the code you have posted in your earlier questions and the code you have posted here :

In the earlier questions , the companies were in column F in the tab named HDD , and in column CF in the tab named Source ; the segment was in column E in the tab named HDD , and in column CB in the tab named Source.

In this question , what ever is in column F in the tab named HDD is being used as a criterion for what ever is in column CG in the tab named Source ; what ever is in column E in the tab named HDD is being used as a criterion for what ever is in column CB in the tab named Source ; what ever is in column D in the tab named HDD is being used as a criterion for what ever is in column CC in the tab named Source.

The above is for the first two SUMIFS formulae.

For the next two SUMIFS formulae , it is as follows :

What ever is in column F in the tab named HDD is being used as a criterion for what ever is in column CC in the tab named Source ; what ever is in column E in the tab named HDD is being used as a criterion for what ever is in column CB in the tab named Source.

Can you verify that these are all correct ?

Narayan
 
Back
Top