+ Reply to Thread
Results 1 to 5 of 5

Compile Error syntax error

Hybrid View

  1. #1
    Registered User
    Join Date
    02-23-2014
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    5

    Compile Error syntax error

    An error appears when using the user form
    this is the part of the code that is wrong according to excel, if someone could help me out id appreciate it so much.

    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    This is the full code:

     Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    
    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
    'check for a Name number
    If Trim(Me.textbox_name.Value) = "" Then
    Me.textbox_name.SetFocus
    MsgBox "Please complete the form"
    Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.textbox_name.Value
    ws.Cells(iRow, 2).Value = Me.textbox_surname.Value
    ws.Cells(iRow, 3).Value = Me.textbox_age.Value
    ws.Cells(iRow, 4).Value = Me.textbox_gender.Value
    
    MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
    'clear the data
    Me.textbox_name.Value = ""
    Me.textbox_surname.Value = ""
    Me.textbox_age.Value = ""
    Me.textbox_gender.Value = ""
    Me.textbox_name.SetFocus
    Last edited by ixelister; 02-23-2014 at 03:16 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Compile Error syntax error

    Remove the _.

    Oh, and please edit your post to add code tags - there's a link in my signature.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-23-2014
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Compile Error syntax error

    Now the bit in bold is the problem. Compile error method or data member not found

    'check for a Name number
    If Trim(Metextbox_name.Value) = "" Then
    Me.textbox_name.SetFocus
    MsgBox "Please complete the form"
    Exit Sub
    End If
    Last edited by Leith Ross; 02-23-2014 at 03:24 PM. Reason: Added Code Taags

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Compile Error syntax error

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  5. #5
    Registered User
    Join Date
    02-23-2014
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Compile Error syntax error

    i apoligise, i have changed it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. [SOLVED] first timer using VB to cut and paste macro - getting compile error syntax error
    By jopedder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2013, 11:45 AM
  3. [SOLVED] Compile Error : Syntax Error
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2013, 08:29 AM
  4. [SOLVED] Compile Error: Expected Expression, Syntax Error
    By gjohn282 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 11:28 PM
  5. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1