So, I have created a pretty extensive macro and I am updating/appending to it.
Long story short, the following line triggers the run-time 1004 error, but I do not know why.
ActiveCell.FormulaR1C1 = _ "=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""100-E"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Allen-Bradley® Bulletin 100-E contactors reduce width and weight while saving panel space. With the universal electronic AC/DC coil, selection is easier than ever. And they offer significant energy savings and direct PLC connection. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the Bulletin 100-E product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley is a trademark of Rockwell Automation."",RC[1])"
This line is contained within a Do While Loop with Multiple If statements underneath it. That is show below:
.
.
.
.
X = 1
Do While X < 53
If X = 1 Then
ActiveCell.FormulaR1C1 = _
"=IF(AND(LEFT(RC[" & cn_dif & "],4)=""809S"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Get state-of-the-art supplementary protection with Allen-Bradley® Bulletin 809S current monitoring relays. They are easy to add and apply to your motor control circuits. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the 809S product family. For more detail, please see the product detail sections below."" & CHAR(10) & ""Allen-Bradley is a trademark of Rockwell Automation."","""")"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
ElseIf X = 2 Then
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""150-F"",RC[" & brand_dif & "]=""Allen-Bradley®""),""With advanced performance, diagnostics, and protection, Allen-Bradley® SMC™ Flex soft starters feature integral bypass and flexible communications. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the SMC Flex product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley and SMC are trademarks of Rockwell Automation."",RC[1])"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
ElseIf X = 3 Then
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""150-C"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Allen-Bradley SMC™-3 soft starters feature compact, three-phase control in a cost-effective package. They include integral bypass and overload protection as well as motor and system diagnostics. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the SMC-3 product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley and SMC are trademarks of Rockwell Automation."",RC[1])"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
ElseIf X = 4 Then
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""100-C"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Space saving, high performance, and low consumption, Allen-Bradley® Bulletin 100-C contactors are designed to control motors and other loads. Catalog item "" & RC[" & cn_dif & "] & "" is a part of the Bulletin 100-C product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley is a trademark of Rockwell Automation."",RC[1])"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
'Why is there always an error here????
ElseIf X = 5 Then '100-E
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""100-E"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Allen-Bradley® Bulletin 100-E contactors reduce width and weight while saving panel space. With the universal electronic AC/DC coil, selection is easier than ever. And they offer significant energy savings and direct PLC connection. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the Bulletin 100-E product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley is a trademark of Rockwell Automation."",RC[1])"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
ElseIf X = 6 Then
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]="""",RC[1]="""",LEFT(RC[" & cn_dif & "],5)=""100-G"",RC[" & brand_dif & "]=""Allen-Bradley®""),""Get reliable motor load switching with Allen-Bradley® Bulletin 100-G contactors. Rockwell Automation® catalog item "" & RC[" & cn_dif & "] & "" is a part of the Bulletin 100-G product family. For more detail, please see the product detail sections below. & CHAR(10) & Allen-Bradley is a trademark of Rockwell Automation."",RC[1])"
Selection.AutoFill Destination:=Range(ActiveCell, Cells(RowCount, ActiveCell.Column))
Range(Cells(2, ActiveCell.Column), Cells(RowCount, ActiveCell.Column)).Select
Call Paste_1_Column_Right
.
.
.
.
.
There are 52 ElseIf Statements, but only the 5th triggers that error (so far).
These formulas are meant to customize a description field based off certain criteria. That criteria being "IF the first X number of characters in the part number are equal to this, THEN input this generic portion of a description with the part number inserted in a specific place".
The variables that you see in the formulas (i.e. cn_dif and brand_dif) are simply the difference between the current columns index location and two other columns (i.e. catalog number and brand name, respectively). This happens for other columns within the macro as well so it can be more dynamic/flexible. This is because the macro is meant to be distributed and run by different people who carry out the tasks in different ways. Therefore, the locations of specific columns are constantly being updated so that nothing needs to be exported or moved around in order for the macro to run.
I have looked at all the quotes, brackets, parentheses, syntax, etc. and everything seems to be fine.
As I said, it is quite an extensive macro so could it have something to do with memory? Should I clear the memory and then redefine the variables in the macro?
It could very well be that I overlooked a bracket or a comma or something was misplaced, but I have been looking at it for a while and cannot figure it out.
Any and all help is accepted. I could post all the code, but it is quite a bit and the block i posted above is the only place the error occurs. All references seem to be good because the macro runs through the first 4 loops in the Do While and then stops at the 5th.
It is because of this that I assumed I missed a comma or something, but I could be wrong and it could be something else entirely.
Just to reiterate it is only when X=5 that this happens (so far).
Also, I know that the CHAR(10) (i.e. carriage return) has no quotes and ampersands around it, but it seems to be working fine and I have tried adding them in, but it did not resolve this issue.
Thank you!
Let me know if you need the full module (it has multiple sub procedures).