+ Reply to Thread
Results 1 to 6 of 6

VBA userform problem with code (syntax error)

Hybrid View

  1. #1
    Registered User
    Join Date
    04-27-2016
    Location
    Manchester
    MS-Off Ver
    Excel
    Posts
    7

    VBA userform problem with code (syntax error)

    Hi Guys

    I am new here and really struggling with VBA, I am trying to get a simple form on excel

    Form.png like this

    I keep getting Syntax error when i click the add data button, Here is the code that is on that button
    Private Sub AddDetails_Click()
    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_Stakes.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_Stakes.Value
    ws.Cells(iRow, 2).Value = Me.TextBox_Struts.Value
    ws.Cells(iRow, 3).Value = Me.TextBox_wire.Value
    ws.Cells(iRow, 4).Value = Me.TextBox_Netting.Value
    ws.Cells(iRow, 5).Value = Me.TextBox_Job.Value
    ws.Cells(iRow, 6).Value = Me.TextBox_Date.Value
    
    MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
    'clear the data
    Me.TextBox_Stakes.Value = ""
    Me.TextBox_Struts.Value = ""
    Me.TextBox_wire.Value = ""
    Me.TextBox_Netting.Value = ""
    Me.TextBox_Job.Value = ""
    Me.TextBox_Date.Value = ""
    Me.TextBox_Stakes.SetFocus
    End Sub
    If anyone could help me out with any advice i would really appreciate it!

    Thanky you very much for taking the time to read this, If you require any additional info please ask
    Last edited by Odowd; 04-27-2016 at 09:18 PM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA beginner HELP

    Hi odowd

    Welcome to forum,
    When you joined the forum recently you agreed to abide by the Forum Rules, but in haste I fear you might not have actually read them. Please stop and take a moment to read them now. We all follow these rules for the benefit of all, as must you. Thanks.

    notably
    Rule 1 - concise titles
    Rule 3 - use [code] Tags
    http://www.excelforum.com/forum-rules/642590-forum-rules.html
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-27-2016
    Location
    Manchester
    MS-Off Ver
    Excel
    Posts
    7

    Re: VBA beginner HELP

    Hi is that better?
    am i able to change the title?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,995

    Re: VBA beginner HELP

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    04-27-2016
    Location
    Manchester
    MS-Off Ver
    Excel
    Posts
    7

    Re: VBA beginner HELP

    Thankyou TMS, a fellow mancunian

    Is there any chance you could help me with my original question? really struggling here

    TIA

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA userform problem with code (syntax error)

    change
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    to
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

+ 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. Beginner help
    By saratu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2014, 02:32 PM
  2. i am a beginner
    By saeedpak13 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-25-2014, 08:42 AM
  3. Beginner!
    By coffeemints in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-28-2013, 07:22 PM
  4. Beginner
    By cawwat85 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-28-2013, 01:34 PM
  5. Beginner If Then Help
    By Than924 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-05-2012, 09:38 AM
  6. Beginner
    By ruhat145 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-01-2012, 10:05 PM
  7. Beginner's help
    By jello in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-08-2005, 12:06 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