Hi,
As per title, I'm trying to populate some formulas from VBA but having problems. This is the UDF and populating sub:
Function GetDateIfValid(DateCell As Range)
On Error GoTo CleanExit
If IsDate(DateCell.Value) And DateCell.Value <= Date And DateCell.Offset(-1, 1) <> "D" Then
GetDateIfValid = DateCell.Value
Exit Function
End If
CleanExit:
GetDateIfValid = ""
Application.Calculate
End Function
Sub populateDatesFormulae()
Dim TC As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each cell In Range("A2:A60")
TC = Cells(2, (cell.Row - 1) * 3).Address
cell.Formula = "=GetDateIfValid(INDIRECT(""'Employee Tracking'!" & TC & """))"
Next cell
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
When I run it I just get the hourglass until I hit escape. It puts the formula into the first cell correctly but it has a '#VALUE!' error and does not continue with the other cells. If I then hit 'calculate' the formula works fine.
edit - I've now found that if I leave the calculation as automatic it will populate all the cells but still hangs afterwards.
Been messing around for a while with this so any suggestions would be gratefully received.
Thanks,
Chinchin
Bookmarks