New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Compile Error syntax error

Macros, VBA, Excel Automation, etc.

Compile Error syntax error

Postby komisetso » Wed Feb 27, 2013 10:11 am

Good day

Can someone assist me with the following Error, i think the problem is around this code as it highlights it
Code: Select all

Private Sub CommandButton1_Click()

Dim lastrow As Long

  'below code will make user mandatory to fill name and CP and Telephone: and Branch as numeric value

   If Me.TextBox1.Value = “” Then

      MsgBox “Please enter the Name and CP”

      Me.TextBox1.SetFocus


      Exit Sub

   End If
  • 0

komisetso
Rookie
 
Posts: 3
Joined: Feb 27, 2013
Reputation: 0
Excel Version: 2010

Re: Compile Error syntax error

Postby Sisyphus » Thu Feb 28, 2013 3:00 am

Hello komisetso,
Welcome to teh forum!
Off the cuff, I can't see any error in your code. What is the error you get? Can you post the full code and "gutted" workbook?
  • 0

Have a great day! :D

Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)
Sisyphus
Former Moderator
 
Posts: 4454
Joined: Dec 7, 2011
Location: Shanghai
Reputation: 203
Excel Version: 2010

Re: Compile Error syntax error

Postby komisetso » Thu Feb 28, 2013 3:15 am

here is my full code:
and i seem to have another problem again, the combo box is empty
Code: Select all
Private Sub CommandButton1_Click()

Dim lastrow As Long

  below code will make user mandatory to fill name and CP and Telephone: and Branch as numeric value

   If Me.TextBox1.Value = “” Then

      MsgBox “Please enter the Name and CP”

      Me.TextBox1.SetFocus


      Exit Sub

   End If

  If Me.TextBox3.Value = “” Then

     MsgBox “Please enter the Telephone:”

     Me.TextBox3.SetFocus

     Exit Sub

  End If

  If Not IsNumeric(TextBox3.Value) Then

    MsgBox “telephone: should be numeric”

    Me.TextBox3.SetFocus

    Exit Sub

  End If

‘Input data in your excel worksheet

lastrow = Worksheets(“sheet1?).Range(“A65536?).End(xlUp).Row

With Worksheets(“sheet1?).Range(“a1?)

   .Offset(lastrow, 0).Value = lastrow

   .Offset(lastrow, 1).Value = Me.TextBox1.Value

   .Offset(lastrow, 2).Value = Me.ComboBox1.Value

   .Offset(lastrow, 3).Value = Me.TextBox2.Value

   .Offset(lastrow, 4).Value = Me.TextBox3.Value

   .Offset(lastrow, 5).Value = Me.TextBox4.Value

End With

‘clear the form

ComboBox1.Value = “”

TextBox1.Value = “”

TextBox2.Value = “”

TextBox3.Value = “”

TextBox4.Value = “”

End Sub

Private Sub CommandButton2_Click()

   Call UserForm_Initialize

End Sub

Private Sub CommandButton3_Click()

   Unload Me

End Sub

Private Sub UserForm_Initialize()

   TextBox1.Value = “”

   TextBox2.Value = “”

   TextBox3.Value = “”

   TextBox4.Value = “”

With ComboBox1

   .AddItem “Client Card”

   .AddItem “Savings Account”

   .AddItem “Loan”

   .AddItem “ThirdParty details“

   .AddItem “General Info"


End With

ComboBox1.Value = “”

TextBox1.SetFocus

End Sub


EDITED by Sisyphus: Code tags added.
As a courtesy to those who try to help you please always use code tags when publishing code.
  • 0

komisetso
Rookie
 
Posts: 3
Joined: Feb 27, 2013
Reputation: 0
Excel Version: 2010

Re: Compile Error syntax error

Postby Sisyphus » Thu Feb 28, 2013 1:02 pm

Sisyphus wrote:-

What is the error you get? Can you post the full code and "gutted" workbook?
  • 0

Have a great day! :D

Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)
Sisyphus
Former Moderator
 
Posts: 4454
Joined: Dec 7, 2011
Location: Shanghai
Reputation: 203
Excel Version: 2010

Re: Compile Error syntax error

Postby komisetso » Fri Mar 01, 2013 9:51 am

Good day

the error that i am receiving is as folowing ''Compile Error syntax error''
  • 0

komisetso
Rookie
 
Posts: 3
Joined: Feb 27, 2013
Reputation: 0
Excel Version: 2010

Re: Compile Error syntax error

Postby SamT » Fri Mar 01, 2013 10:56 am

I suspect your quote marks. The code you show was not written in VBA. It was created in another editor and copy and pasted into VBA. In your example I see "Smart Quotes," "simple quotes," and "query marks" used as quote marks.

Please use the VBA editor to change all such quotes to the ones used by VBA editor.

Only some examples below, more in your posting.

lastrow = Worksheets(sheet1?).Range(A65536?).End(xlUp).Row

.AddItemGeneral Info"
  • 3

SamT
Excel Junkie
 
Posts: 288
Joined: Feb 28, 2013
Location: Missouri, USA
Reputation: 24
Excel Version: 97+XP+2007+2013


Return to Macros and VBA Questions

Who is online

Users browsing this forum: Google [Bot] and 36 guests

cron