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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
Maybe this?
Cells(4, 34).Formula = "=IF(G4=""no data"",0,AG4*AE4*-1)"
 
Upvote 0

VBA Newbe

New Member
Joined
Mar 4, 2009
Messages
1
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

Ragnar1211

Well-known Member
Joined
Jul 10, 2008
Messages
571
"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

siddharth2008

New Member
Joined
May 22, 2009
Messages
2
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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,351
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
You are missing spaces:
Code:
   rng3.Formula = "=IF(AY" & j & "=""Failed"",1,0)"
 
Upvote 0

Kamusksn

New Member
Joined
Mar 26, 2013
Messages
3
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,190,635
Messages
5,982,050
Members
439,751
Latest member
sohamkhatri

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
Top