Compile Error: Syntax Error

XLerator

New Member
Joined
Apr 10, 2002
Messages
21
I was hoping someone on this board can help me out...

This is what I want it to do:

SUB
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1").Select
ActiveCell.FormulaR1C1 = "TYPE"
Range("C2").Select
ActiveCell.FormulaR1C1 = "IF(L2="Y","Cruise",IF(R2="winter",VLOOKUP(B2,Winter!$A$1:$C$200,2,0),IF(A2="FCO",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2="VCE",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2="SUF",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2="PSR",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),VLOOKUP(B2,Lookup!$A$1:$B$200,2,0)))))))"
Range("C3").Select
LastRow = Range("G1:G" & Range("G1").End(xlDown).Row).Rows.Count
Range("C2" & ":C" & LastRow).FillDown
END SUB

When I type in the BIG formula, it highlights the letter Y (in IF(L2="Y"...)) in brackets and says syntax error---what's going on?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

When writing formulas to the worksheet from VBA, you must enclose all text entries with double double quotes. Also, you formula will fail because you don't enter an equal sign.

Note also that you are inserting a row at col c, and then testing for the number of rows used in col g. Prior to the start of the routine, that col g data was in col F, but the code somewhat "hides" it. Be careful here.


Try the following,
------------------
Sub Test()
Dim lastrow As Long
Columns("C:C").Insert Shift:=xlToRight
Range("C1") = "TYPE"
lastrow = Range("G1:G" & Range("G1").End(xlDown).Row).Rows.Count
Range("C2:C" & lastrow) = "=IF(L2=""Y"",""Cruise"",IF(R2=""winter"",VLOOKUP(B2,Winter!$A$1:$C$200,2,0),IF(A2=""FCO"",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2=""VCE"",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2=""SUF"",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),IF(A2=""PSR"",VLOOKUP(A2,Lookup!$A$1:$B$200,2,0),VLOOKUP(B2,Lookup!$A$1:$B$200,2,0)))))))"
End Sub
-------------------

Bye,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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