Help with VBA syntax error

Skip77

New Member
Joined
Nov 8, 2010
Messages
7
Hello,
I have been trying to put together a macro that will interrogate the contents of a cell and return a value based on the contents (using IF THEN logic). In the Visual Basic window, the code looks like:

Sub Cause1()
'
' Cause1 Macro
'

'
Range("Y2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[10]=""Yes"", ""Red"",
IF(RC[13]=""Yes"", ""Blue"",
IF(RC[14]=""Yes"", ""Green"",
IF(RC[16]=""Yes"", ""Orange"",
IF(RC[17]=""Yes"", ""Purple"",
IF(RC[18]=""Yes"", ""Teal"",
IF(RC[19]=""Yes"", ""Pink"",
IF(RC[20]=""Yes"", ""Black"",
IF(RC[21]=""Yes"", ""Yellow"",
IF(RC[22]=""Yes"", ""Lavender"",
IF(RC[24]=""Yes"", ""White"",
IF(RC[25]=""Yes"", ""Silver"",
IF(RC[27]=""Yes"", ""Gold"",
IF(RC[28]=""Yes"", ""Brown"",
IF(RC[29]=""Yes"", ""Navy Blue"",
IF(RC[1383]=""Yes"", ""Midnight Blue"",
IF(RC[32]=""Yes"", ""Magenta"",
IF(RC[33]=""Yes"", ""Violet"",
IF(RC[34]=""Yes"", ""Turquoise"",
IF(RC[35]=""Yes"", ""Adobe"",
IF(RC[36]=""Yes"", ""Concrete"",
IF(RC[37]=""Yes"", ""Earth"",
IF(RC[38]=""Yes"", ""Mud"",
IF(RC[11]<>"""", ""Building ""&RC[11],
IF(RC[12]<>"""", ""House ""&RC[12],
IF(RC[15]<>"""", """"&RC[15],
IF(RC[23]<>"""", ""Factory ""&RC[23])))))))))))))))))))))))))))"
Range("Y3").Select
End Sub

I tried to develop this in a bullet point format as when I tried the code on the "linear" fashion it seemed to break at the line return (despite my trying _).

Hoping someone can take a look and let me know where I am off track. When I try to run the macro I receive a Compile Error: Syntax Error on line 2 (RC 13)

Thank You,

Skip
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What exactly are you trying to achieve? I can see the syntax error with your code, but without understanding what your aim is, there are various corrections that can be suggested..
 
Upvote 0
if u have a line break in the code use an underscore as shown below.

Code:
"=IF(RC[10]=""Yes"", ""Red"", _
IF(RC[13]=""Yes"", ""Blue"",

hope it helps...
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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