VBA: Compile error: Expected end of statement

marco84

New Member
Joined
Jun 18, 2008
Messages
2
Hi,

I'd like to enter a Formula into a specific Cell:
Cells(4, 34).Value = "=IF(G4="no data",0,AG4*AE4*-1)"

I can't proceed and get the compile error, the "no data" seems to be the problem, but I need it for the if-statement.

Any idea how to solve that?

Thanks
marco
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe this?
Cells(4, 34).Formula = "=IF(G4=""no data"",0,AG4*AE4*-1)"
 
Upvote 0
Hi there,

I'm new to MrExcel and I have a similar challenge!

I have written the following code and receive a 'Compile error: Expected end of statement' message too...

Range("L22").Select
If ActiveCell.Formula = "True" Then
ActiveSheet.Outline.ShowLevels RowLevels:=1

Else ActiveCell.Formula = "False" Then
ActiveSheet.Outline.ShowLevels RowLevels:=2
End If

End Sub

Any assistance would be greatly appreciated.
Cheers
 
Upvote 0
"Else" does not require a "Then" statement. Else means - if you get here do this. Remove the "ActiveCell.Formula = "False" Then" and you should be good.
 
Upvote 0
Hi,

I am trying to build a formula in VBA bu getting the same error on the following line:

rng3.Formula="=IF(AY"&j&"=""Failed"",1,0)"

Here, rng3 is a defined range, and j is an integer to pick row number.

Can you please help.
 
Upvote 0
You are missing spaces:
Code:
   rng3.Formula = "=IF(AY" & j & "=""Failed"",1,0)"
 
Upvote 0
I'm trying to set a formula in a spesific field

'This code insert the formula
Dim Formula As String
Formula = _
"=COUNTA(F2:F25000)"
Range("R2").Formula = Formula

'This code not inset the formula [Runtime Error 1404 "Application-Deffined or Objet-Deffined error]
Dim Formula As String
Formula = "=IF(AND(C2="",A2<>""CC"",A2<>""PF"",A2<>""PU"",A2<>""40""),16,A2)"
Range("P2").Formula = Formula

any know why?
Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,974
Members
448,934
Latest member
audette89

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