Excel VBA - Evaluate MIN with two criteria not working

atame

New Member
Joined
May 26, 2015
Messages
31
I am currently writing a piece of code, that finds the first date of something for two categories, in the cells.

If one of the cells has a date filled in, it ignores it but if the other cell is blank it runs the evaluate formula.

The problem I am having is the code formula works on the sheet, but not in the code I get Error: "Run-time error '1004': Application-defined or object-defined error."

The code is failing on the
Code:
xMinScaff = Evaluate("=MIN(IF('Instruction History'!$D:$D=" & cell.address(False, False) & ",IF('Instruction History'!$E:$E=""Scaffold Req"",'Instruction History'!$H:$H)))")
and i would also asumme it will fail on
Code:
xMinWorks = Evaluate("=MIN(IF('Instruction History'!$D:$D=" & cell.address(False, False) & ",IF('Instruction History'!$E:$E<>""Scaffold Req"",'Instruction History'!$H:$H)))")
as they are pretty identical.

Here is the code I currently have. Thanks

Code:
Private Sub CommandButton4_Click()
Dim cell, cellRange As Range
Dim lastRow As Long
Dim xMinScaff, xMinWorks As Variant


lastRow = sheets("Current Asset List").cells(Rows.count, "A").End(xlUp).Row
Set cellRange = sheets("Current Asset List").Range("A8:A" & lastRow)


For Each cell In cellRange
    If cell.Offset(0, 24) = "" Then
        xMinScaff = Application.Evaluate("=MIN(IF('Instruction History'!$D:$D=" & cell.address(False, False) & ",IF('Instruction History'!$E:$E=""Scaffold Req"",'Instruction History'!$H:$H)))")
        If xMinScaff <> "0" Then
            cell.Offset(0, 24).value = Format(xMinScaff, "DD/MM/YYYY")
        End If
    End If
    If cell.Offset(0, 25) = "" Then
        xMinWorks = Application.Evaluate("=MIN(IF('Instruction History'!$D:$D=" & cell.address(False, False) & ",IF('Instruction History'!$E:$E<>""Scaffold Req"",'Instruction History'!$H:$H)))")
        If xMinWorks <> "0" Then
            cell.Offset(0, 25).value = Format(xMinWorks, "DD/MM/YYYY")
        End If
    End If
Next cell
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,216,604
Messages
6,131,700
Members
449,666
Latest member
Tommy2Tables365

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