I have a code that sums my items if it finds NOMINAL_MAX. However, I would like to add a condition > 0. when i add it i get a "Type mismatch" error. How to fix it ?
With wbMe.Worksheets("pochodne")
WYCENA_po_CVA_DVA = "WYCENA_po_CVA_DVA"
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
Set rTable = .Range(.Cells(1, 1), .Cells(LastRow, LastCol))
Set rCol = rTable.Rows(1).Find(What:=WYCENA_po_CVA_DVA, LookIn:=xlValues, LookAt:=xlWhole)
If Not rCol Is Nothing Then
.Range("T35").Value = Application.WorksheetFunction.Sum(rTable.Columns(rCol.Column) > 0)
Else
SumCriteria = CVErr(xlErrValue)
End If
End With
CodePudding user response:
You can use sumif in this way:
With Worksheets("pochodne")
WYCENA_po_CVA_DVA = "WYCENA_po_CVA_DVA"
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
Set rTable = .Range(.Cells(1, 1), .Cells(LastRow, LastCol))
Set rCol = rTable.Rows(1).Find(What:=WYCENA_po_CVA_DVA, LookIn:=xlValues, LookAt:=xlWhole)
If Not rCol Is Nothing Then
.Range("T35").Value = Application.WorksheetFunction.SumIf(rTable.Columns(rCol.Column), ">0")
Else
SumCriteria = CVErr(xlErrValue)
End If
End With
