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
and i would also asumme it will fail on
as they are pretty identical.
Here is the code I currently have. Thanks
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)))")
Code:
xMinWorks = Evaluate("=MIN(IF('Instruction History'!$D:$D=" & cell.address(False, False) & ",IF('Instruction History'!$E:$E<>""Scaffold Req"",'Instruction History'!$H:$H)))")
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