I know there's a bazillion of these questions out there; but I've tried implementing things from various ones I've seen and haven't hit upon the right structure yet. I keep getting application/object defined errors. I'm sure it's the quotation marks but I can't seem to figure out where I have too many vs not enough. The end goal is for this formula to appear after a certain range of rows (newrows variable) and update dynamically as it fills down each row after that.
I've tried removing the extra quotes around the string sections, but it then gives me an "Expected: end of statement" error near the beginning of the code. When I'm viewing it in Notepad ++ it looks correct, but still get the errors in VBA itself when running the macro in excel.
Range("R" & newrows & ":R1000").Formula = "=iferror(IF(""E""" & newrows & "= ""Planning"",VLOOKUP(""D""" & newrows & ",DataCheck4!A:F,3,FALSE),IF(""E""" & newrows & "=""Fieldwork"",VLOOKUP(""D""" & newrows & ",DataCheck4!A:F,4,FALSE),IF(""E""" & newrows & "=""Reporting"",VLOOKUP(""D""" & newrows & ",DataCheck4!A:F,5,FALSE),IF(""E""" & newrows & "=""Wrap Up"",VLOOKUP(""D""" & newrows & ",DataCheck4!A:F,6,FALSE),IF(""E""" & newrows & "=""Proj. Mgmt"",VLOOKUP(""D""" & newrows & ",DataCheck4!A:F,6,FALSE),"""")))))"
The code is supposed to be looking up a value based on the value of a cell in a row (Column E) and the name of a project (Column D). The newrows is a numerical variable being generated by a dynamic list. The top portion of the sheet has existing tasks I don't want to overwrite but I want this formula in all cells after the end row of that list. I've been learning VBA as I've been working on this project so it may be something I just haven't come across yet so I appreciate the help!
ETA: This morning I tried turning the sequence with newrows into a variable with the column letter instead and got the same application defined error.
firstloc = "E" & newrows
secondloc = "D" & newrows
Range("R" & newrows & ":R1000").Formula = "=iferror(IF(" & firstloc & "= ""Planning"",VLOOKUP(" & secondloc & ",DataCheck4!A:F,3,FALSE),IF(" & firstloc & "=""Fieldwork"",VLOOKUP(" & secondloc & ",DataCheck4!A:F,4,FALSE),IF(" & firstloc & "=""Reporting"",VLOOKUP(" & secondloc & ",DataCheck4!A:F,5,FALSE),IF(" & firstloc & "=""Wrap Up"",VLOOKUP(" & secondloc & ",DataCheck4!A:F,6,FALSE),IF(" & firstloc & "=""Proj. Mgmt"",VLOOKUP(" & secondloc & ",DataCheck4!A:F,6,FALSE),"""")))))"
...IF(E" & newrows ...and repeat that change in other places.Range("R" & newrows & ":R1000").Formula =withDebug.Print, then run it and see what gets printed into the immediate pane (Ctrl+G) - then take that output, copy it, and paste it into a cell - Excel will complain about the formula being invalid; fix the formula in Excel, then go back to the code and fix accordingly."in the output string you want, needs to be escaped, i.e. doubled-up; soa = """"is assigning a string literal that contains a single"double-quote character. The reason for this is that the"character happens to be the string literal delimiter token, so that character needs to be escaped somehow if it needs to appear in a string literal: in VBA you escape double quotes by doubling them, is all.