Excel vba application-defined or object-defined error

dgrimm

Board Regular
Joined
Sep 17, 2007
Messages
159
I am getting an error EXCEL VBA APPLICATION-DEFINED OR OBJECT-DEFINED ERROR on the last line of the loop. I have looked it up but with nothing applying that I have read.

For i = 1 To PatCnt - 1

Range("E" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(" & """Patient:""" & "," & "PatientL" & i & ",3,FALSE))," & """""" & ",VLOOKUP(" & """Patient:""" & "," & "PatientL" & i & ",3,FALSE))"
Range("F" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(" & """Primary:""" & "," & "PatientL" & i & ",3,FALSE))," & """""" & ",VLOOKUP(" & """Primary:""" & "," & "PatientL" & i & ",3,FALSE))"
Range("G" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(" & """Secondary:""" & "," & "PatientL" & i & ",3,FALSE))," & """""" & ",VLOOKUP(" & """Secondary:""" & "," & "PatientL" & i & ",3,FALSE))"
Range("H" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(" & """Patient Total:""" & "," & "PatientL" & i & ",43,FALSE))," & """""" & ",VLOOKUP(" & """Patient Total:""" & "," & "PatientL" & i & ",4,FALSE))"
Range("I" & i + 1).Formula = _
"=IF(OR(AND(CELLS(" & """E""" & i + 1 & ") = """""" & "",CELLS(" & """F""" & i + 1 & ")=" & """""" & ",CELLS(" & """G""" & i + 1 & ")=" & """""" & "),MAX(CELLS(" & """E""" & i + 1 & "):CELLS(" & """G""" & i + 1 & "))>NOW()-365)," & "OK" & "," & "Dated" & ")"""

Next i

the vlookups work fine it is the if(or(and line that is messing up.

Any help would be greatly appreciated.

Thanks

David
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try

Code:
Range("I" & i + 1).Formula = _
"=IF(OR(COUNT(E" & i + 1 & ":G" & i + 1 & ")=0,MAX(E" & i + 1 & ":G" & i + 1 & ")>NOW()-365),""OK"",""Dated"")"

I took the lliberty of changing
AND(Ei+1="",Fi+1="",Gi+1="")
to
COUNT(Ei+1:Gi+1)=0

MUCH easier to write in code, and should give same results.
 
Upvote 0
Also, you are way overcomplicating the process of concatenating variables into a formula...

When the end result of the formula you want contains quotes
you just have to double up those quotes.
You don't have to concatenate in a new string of quotes..

The only part(s) that requires concatenation is the variable (i)


This
Code:
Range("E" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(" & """Patient:""" & "," & "PatientL" & i & ",3,FALSE))," & """""" & ",VLOOKUP(" & """Patient:""" & "," & "PatientL" & i & ",3,FALSE))"
can be changed to
Code:
Range("E" & i + 1).Formula = _
"=IF(ISNA(VLOOKUP(""Patient:"",PatientL" & i & ",3,FALSE)),"""",VLOOKUP(""Patient:"",PatientL" & i & ",3,FALSE))"

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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