+ Reply to Thread
Results 1 to 11 of 11

2 different errors im struggling with

Hybrid View

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

    Re: 2 different errors im struggling with

    This should sort the first error.
    Private Sub btnAdd_Click()
    Dim ws As Worksheet
    Dim i As Variant
    Dim newRow As Long
    
        Set ws = Worksheets("Overstocks")
    
        newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
    
    
        ws.Cells(newRow, 1).Value = Me.txtBrand.Value
        ws.Cells(newRow, 2).Value = Me.cbCategory.Value
        ws.Cells(newRow, 3).Value = Me.txtQuantity.Value
        ws.Cells(newRow, 4).Value = IIf(opYes.Value, "Yes", "No")
        ws.Cells(newRow, 5).Value = Date
    
        Clear_Form
    
        'validate textbox entry
        Dim ctrl As Control
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is MSForms.TextBox Then
                If ctrl.Value = vbNullString Then
                    MsgBox "You must complete all entries"
                    ctrl.SetFocus
                    Unload Me
                  Exit Sub
                End If
            End If
        Next ctrl
        
    End Sub
    Not sure where to look for the other code that's causing problems, where is that located?
    If posting code please use code tags, see here.

  2. #2
    Registered User
    Join Date
    01-26-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    15

    Re: 2 different errors im struggling with

    Quote Originally Posted by Richard Buttrey View Post
    Hi and welcome to the forum

    At the moment you have two IF statements and only one End If. They should be paired.

    You also have a For Each Ctrl without a Next Ctrl
    Thank you both for your input and really quick replies!

    Thanks Richard, I'll have a look at some YouTube videos about that. Random question is there anyone online you who's videos you recommend? I feel like I'm not learning the important basics, with the current videos I'm watching.

    Quote Originally Posted by Norie View Post
    This should sort the first error.
    Private Sub btnAdd_Click()
    Dim ws As Worksheet
    Dim i As Variant
    Dim newRow As Long
    
        Set ws = Worksheets("Overstocks")
    
        newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
    
    
        ws.Cells(newRow, 1).Value = Me.txtBrand.Value
        ws.Cells(newRow, 2).Value = Me.cbCategory.Value
        ws.Cells(newRow, 3).Value = Me.txtQuantity.Value
        ws.Cells(newRow, 4).Value = IIf(opYes.Value, "Yes", "No")
        ws.Cells(newRow, 5).Value = Date
    
        Clear_Form
    
        'validate textbox entry
        Dim ctrl As Control
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is MSForms.TextBox Then
                If ctrl.Value = vbNullString Then
                    MsgBox "You must complete all entries"
                    ctrl.SetFocus
                    Unload Me
                  Exit Sub
                End If
            End If
        Next ctrl
        
    End Sub
    Not sure where to look for the other code that's causing problems, where is that located?
    I added that code Norie thank you very much. The problem I'm still having is even though i don't complete the userform, it still automatically adds the IST 'no' section. How do i rectify this? The second error is located in module 2, no idea how I've ended up putting it there lol.

+ 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. Struggling with IF
    By KClark in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-10-2011, 04:37 AM
  2. struggling
    By Tomas mcD in forum Excel General
    Replies: 1
    Last Post: 03-07-2011, 08:25 AM
  3. [SOLVED] Excel Throwing Circular Errors When No Errors Exist
    By MDW in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-10-2006, 09:20 AM
  4. Struggling IF value
    By Rebecca in forum Excel General
    Replies: 5
    Last Post: 04-06-2006, 04:55 PM
  5. Help, I'm Struggling!
    By Fybo in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-04-2005, 04:06 PM

Tags for this Thread

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