KG Old Wolf
Board Regular
- Joined
- Sep 20, 2009
- Messages
- 65
Goal: use "If" formula in R1C1 to evaluate cell contents; if "true" use Variable, if "false" use Constant
Issue: Constant works fine in all code snippets. Variable works fine when a number (Work_2) but FAILS when text (Work_1). Following are 3 different approaches I've tried to no avail. I've spent a full day researching and testing and got nowhere getting the string variable to work. The formula that appears in the cell is the correct string value (Old Wolf) but it is equating to a #NAME error message because it is not in quotes.
Recommendations for correct syntax and reading lists will be greatly appreciated. Here are the code snippets. What am I missing?
Thanks
--------------------------------------------------------------
Dim Work_1 As String
Dim Work_2 As Long
Dim Hope As String
'
Work_1 = "Old Wolf"
Work_2 = 2468
'
'
Range(Cells(10, 2), Cells(14, 2)).FormulaR1C1 = "=IF(R[-8]C[-1]=3,Work_1,R[-8])"
'
'
Range(Cells(10, 3), Cells(14, 3)).FormulaR1C1 = "=IF(R[-8]C[-2]=3," & Work_1 & ",R[-8])"
'
'
Hope = "=if(R[-8]=3," & Work_1 & ",R[-8])"
Range(Cells(10, 1), Cells(14, 1)).FormulaR1C1 = Hope
'
Issue: Constant works fine in all code snippets. Variable works fine when a number (Work_2) but FAILS when text (Work_1). Following are 3 different approaches I've tried to no avail. I've spent a full day researching and testing and got nowhere getting the string variable to work. The formula that appears in the cell is the correct string value (Old Wolf) but it is equating to a #NAME error message because it is not in quotes.
Recommendations for correct syntax and reading lists will be greatly appreciated. Here are the code snippets. What am I missing?
Thanks
--------------------------------------------------------------
Dim Work_1 As String
Dim Work_2 As Long
Dim Hope As String
'
Work_1 = "Old Wolf"
Work_2 = 2468
'
'
Range(Cells(10, 2), Cells(14, 2)).FormulaR1C1 = "=IF(R[-8]C[-1]=3,Work_1,R[-8])"
'
'
Range(Cells(10, 3), Cells(14, 3)).FormulaR1C1 = "=IF(R[-8]C[-2]=3," & Work_1 & ",R[-8])"
'
'
Hope = "=if(R[-8]=3," & Work_1 & ",R[-8])"
Range(Cells(10, 1), Cells(14, 1)).FormulaR1C1 = Hope
'