Hi. I am having an issue with a macro I wrote that reformats a report I receive in Excel. One of the commands looks for the blank cells in column A and based on the content of column C, enters the appropriate value. Frequently, when I run the macro I get "Run-time error '1004' Application-defined or object defined error" and when I click on Debug, it highlights the blue line of code:
Columns("A:A").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = _
"=+IF(ISNUMBER(SEARCH(""CSC"",RC[2])),""Phn-Dsk"",IF(RC[2]=""TGR1"",""TGR1"",IF(RC[2]=""EST-A"",""TRP"",IF(RC[2]=""EST-D"",""TRP"",IF(RC[2]=""1154"",""Phn-Dsk"",IF(RC[2]=""1164"",""Phn-Dsk"",IF(RC[2]=""5"",""Phn-Dsk"",IF(RC[2]=""10"",""Phn-Dsk"",IF(RC[2]=""11"",""Phn-Dsk"",IF(RC[2]=""13"",""Phone-Desk"",""ERROR""))))))))))"
The odd thing is that it doesn't error every time. It's almost like if you try enough times, eventually it gives in and runs through. I have tried breaking the statement down into individual IF/THEN statements, but it doesn't work. In that case, even through I said to leave the field blank if it didn't meet the criteria, it pastes in the formula.
Any idea why I am getting the error message and how I can work around it? I would appreciate any help you can give. Thank you.
Columns("A:A").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = _
"=+IF(ISNUMBER(SEARCH(""CSC"",RC[2])),""Phn-Dsk"",IF(RC[2]=""TGR1"",""TGR1"",IF(RC[2]=""EST-A"",""TRP"",IF(RC[2]=""EST-D"",""TRP"",IF(RC[2]=""1154"",""Phn-Dsk"",IF(RC[2]=""1164"",""Phn-Dsk"",IF(RC[2]=""5"",""Phn-Dsk"",IF(RC[2]=""10"",""Phn-Dsk"",IF(RC[2]=""11"",""Phn-Dsk"",IF(RC[2]=""13"",""Phone-Desk"",""ERROR""))))))))))"
The odd thing is that it doesn't error every time. It's almost like if you try enough times, eventually it gives in and runs through. I have tried breaking the statement down into individual IF/THEN statements, but it doesn't work. In that case, even through I said to leave the field blank if it didn't meet the criteria, it pastes in the formula.
Any idea why I am getting the error message and how I can work around it? I would appreciate any help you can give. Thank you.