Using a complex function in VBA

moric11

New Member
Joined
Nov 20, 2016
Messages
3
Hi everyone!

I have a big problem. I would like to put in an excel funtion to VBA but it makes "Compile error: Syntax error"

Here it is the code:

Private Sub CommandButton2_Click()
Range("E12").Value = Appliaction.WorksheetFunction.If(CountA(C34:D51)>1;"VEGYES paletta";E34)
End Sub


Can you help me?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
There is no Worksheet.If in VBA, if you want to use If in code try this.
Code:
Private Sub CommandButton2_Click()
Dim Res As Variant
    
    Res = Application.CountA(Range("C34:D51"))

    If Res > 1 Then
        Range("E12").Value = "VEGYES paletta"
    Else 
        Range("E12").Value = Range("E34").Value
    End If

End Sub
 
Upvote 0
Welcome to the board.

Code:
Private Sub CommandButton2_Click()
  Range("E12").Value = Evaluate("if(counta(C34:D51) > 1, ""VEGYES paletta"", E34)")
End Sub
 
Upvote 0
Code:
Range("E12").Formula = "=if(counta(C34:D51) > 1; ""VEGYES paletta""; E34)"
 
Upvote 0
[...Deleted...]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,956
Members
449,200
Latest member
indiansth

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