vba for sumif formula

shiva_reshs

Board Regular
Joined
Sep 5, 2012
Messages
68
Hello,

Whats wrong with my sumif function?

Code:
Sub update2()Dim x As Workbook
Dim y As Workbook




ImportDir1 = Trim(Sheets("Control").Range("H6").Value)
Application.DisplayAlerts = False


Set x = Workbooks.Open(ImportDir1 & "\" & Sheets("Control").Range("C6").Value & ".xlsx")
With x.Sheets(1)
Sheets(1).AutoFilterMode = False
End With
Application.DisplayAlerts = True
    'x.Close
Workbooks("Validation.xlsm").Activate
Application.DisplayAlerts = False
Set y = Workbooks.Open(ImportDir1 & "\" & Trim(Sheets("Control").Range("C7").Value) & ".xlsx")
Application.DisplayAlerts = True
With y.Sheets(1)
Sheets(1).AutoFilterMode = False
   End With
   
 
    Dim lastrow As Long
    Dim i As Long
    x.Activate
    lastrow = Range("B" & Rows.Count).End(xlUp).Row
    For i = 8 To lastrow
        If Range("B" & i).Value <> "" Then
          Range("Y" & i).Formula = "=IFERROR(VLOOKUP(RC[-23],'[" & y.Name & "]July 18 OT New Formula'!C2:C13,8,0),0)"
             Range("AB" & i).Formula = "=IFERROR(VLOOKUP(RC[-26],'[" & y.Name & "]July18 Night Shift Allowance'!C2:C13,6,0),0)"
[COLOR=#b22222]             Range("AV" & i).Formula = "=IFERROR(SUMIFS('[" & y.Name & "]Medical Claim'!C8,'[" & y.Name & "]Medical Claim'!C2,RC[-46],0)"[/COLOR]
               
               Range("AW" & i).Formula = "=IFERROR(VLOOKUP(RC[-47],'[" & y.Name & "]Meal Allowance '!C2:C13,6,0),0)"
             
                 
             
        End If
    Next i
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Am sorry, just saw Iferror which is not valid in sumiffs. below works out fine.

Code:
 Range("AV" & i).Formula = "=SUMIFS('[" & y.Name & "]Medical Claim'!C8,'[" & y.Name & "]Medical Claim'!C2,RC[-46])"
 
Upvote 0

Forum statistics

Threads
1,223,787
Messages
6,174,561
Members
452,573
Latest member
Cpiet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top