+ Reply to Thread
Results 1 to 8 of 8

UserForm : Update List is not working : Solved by ( jaslake)

Hybrid View

  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Thumbs up UserForm : Update List is not working : Solved by ( jaslake)

    I want to update automatically list but there is error :

    Compile error:

    Block if without End If


    Private Sub ComboBox1_Change()
    Dim NewEntry As String
    
    If Target.Cells.Count > 1 Then Exit Sub
    If Target = "" Then Exit Sub
    
    If Not Intersect(Target, Range("a1:a11")) Is Nothing Then
        NewEntry = ""
        NewEntry = Target
       If WorksheetFunction.CountIf(Sheet1.Range("data"), NewEntry) = 0 Then
          Application.EnableEvents = False 'Prevent Change Event Firing again while code is running.
          'Ask if they wish to add the name or not.
              iReply = MsgBox("The name " & Target & _
                       " is not part of the list, do you wish to add it.", _
                        vbYesNoCancel + vbQuestion, "HaroonSid.com")
                If iReply = vbCancel Then 'Cancelled so restore orginal text
                   Target = strOriginalEntry
                ElseIf iReply = vbNo Then
                'Don't add to list. That is do nothing
                Else
                Application.EnableEvents = True
    
    TextBox1.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 2, 0)
    TextBox2.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 3, 0)
    TextBox3.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 4, 0)
    TextBox4.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 5, 0)
    TextBox5.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 6, 0)
    TextBox6.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 7, 0)
    
    End Sub
    
    Private Sub CommandButton1_Click()
    Dim ctl
        For Each ctl In Me.Controls
            If TypeOf ctl Is Msforms.TextBox Then
                ctl.Text = ""
            End If
        Next ctl
    End Sub
    
    Private Sub CommandButton2_Click()
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 1) = TextBox1.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 2) = TextBox2.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 3) = TextBox3.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 4) = TextBox4.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 5) = TextBox5.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 6) = TextBox6.Text
    
    
    
    
    MsgBox ("Record Updated")
    End Sub
    
    
    
    Private Sub CommandButton3_Click()
    
        Range("B2:G11").Select
        Selection.ClearContents
      Range("A1").Select
    End Sub
    
    Private Sub CommandButton4_Click()
    Unload Me
    End Sub
    
    Private Sub UserForm_Activate()
        Me.ComboBox1.List = Worksheets("Data").Range("A2:A11").Value
        
        
    End Sub
    Attached Files Attached Files
    Last edited by HaroonSid; 03-23-2014 at 01:02 AM. Reason: solved

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: UserForm : Update List is not working

    This compiles...
    Private Sub ComboBox1_Change()
        Dim NewEntry As String
    
        If Target.Cells.Count > 1 Then Exit Sub
        If Target = "" Then Exit Sub
    
        If Not Intersect(Target, Range("a1:a11")) Is Nothing Then
            NewEntry = ""
            NewEntry = Target
            If WorksheetFunction.CountIf(Sheet1.Range("data"), NewEntry) = 0 Then
                Application.EnableEvents = False    'Prevent Change Event Firing again while code is running.
                'Ask if they wish to add the name or not.
                iReply = MsgBox("The name " & Target & _
                              " is not part of the list, do you wish to add it.", _
                                vbYesNoCancel + vbQuestion, "HaroonSid.com")
                If iReply = vbCancel Then    'Cancelled so restore orginal text
                    Target = strOriginalEntry
                ElseIf iReply = vbNo Then
                    'Don't add to list. That is do nothing
                Else    'Add the new name to the cell below the last name in the named range "Name_SID"
                    Application.EnableEvents = True
    
                    TextBox1.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 2, 0)
                    TextBox2.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 3, 0)
                    TextBox3.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 4, 0)
                    TextBox4.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 5, 0)
                    TextBox5.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 6, 0)
                    TextBox6.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 7, 0)
                End If
            End If
        End If
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: UserForm : Update List is not working

    an error :

    (Run-time error '424'

    Object required )

    If Target.Cells.Count > 1 Then

  4. #4
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: UserForm : Update List is not working

    the original code is this

    in this code i want to add a new name or not and update data

    Private Sub ComboBox1_Change()
                    TextBox1.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 2, 0)
                    TextBox2.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 3, 0)
                    TextBox3.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 4, 0)
                    TextBox4.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 5, 0)
                    TextBox5.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 6, 0)
                    TextBox6.Text = Application.WorksheetFunction.VLookup(ComboBox1.Value, Range("A1:g11"), 7, 0)
                End If
            End If
        End If
    End Sub
    
    Private Sub CommandButton1_Click()
    Dim ctl
        For Each ctl In Me.Controls
            If TypeOf ctl Is Msforms.TextBox Then
                ctl.Text = ""
            End If
        Next ctl
    End Sub
    
    Private Sub CommandButton2_Click()
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 1) = TextBox1.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 2) = TextBox2.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 3) = TextBox3.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 4) = TextBox4.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 5) = TextBox5.Text
    
    rownum = Application.WorksheetFunction.Match(ComboBox1.Text, Range("a:a"), 0) - 1
    Range("a1").Offset(rownum, 6) = TextBox6.Text
    
    MsgBox ("Record Updated")
    End Sub
    
    
    
    Private Sub CommandButton3_Click()
    
        Range("B2:G11").Select
        Selection.ClearContents
      Range("A1").Select
    End Sub
    
    Private Sub CommandButton4_Click()
    Unload Me
    End Sub
    
    Private Sub UserForm_Activate()
        Me.ComboBox1.List = Worksheets("Data").Range("A2:A11").Value
        
        
    End Sub

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

    Re: UserForm : Update List is not working

    You want to add a new name to what?

    Where does the new name come from?
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: UserForm : Update List is not working

    Hello Norie FG

    First u download the sample file
    when u click Show Form
    UserForm1 will pop up
    in Lable "name" i defined a list ( range "a1:a11" ) in Combobox1
    i choose a name from combobox and add some data

    if i type a new name which is not in list then
    a msgbox appers and ask ("do u want to add this name to list") if
    i choose yes then this new name should be add in list (ragne "a1:a11")
    and also record should be update

    thanx

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: UserForm : Update List is not working

    Hi haroon2015

    I rewrote the Code rather than attemp to modify yours. Your use of Target Cells is inappropriate in this instance. The Code in the attached is a modification of this
    '---------------------------------------------------------------------------------------
    ' Module : Database Form
    ' DateTime : 31/08/2005 10:55. Updatede 08-02-08
    ' Author : Roy Cox
    ' Modified : jaslake 03/21/2014
    ' Purpose : Data entry form for Excel, with Search facility
    '---------------------------------------------------------------------------------------
    Attached Files Attached Files

  8. #8
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: UserForm : Update List is not working

    hello jaslake


    Simply Just Awsome


    thanx a lot very much for ur hardwork

+ 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. update value and edit items already update on sheet by userform
    By tjxc32m in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-08-2013, 10:13 AM
  2. Search records from userform and update data list
    By craigw27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2013, 08:55 AM
  3. Update excel based on userform text box update
    By sivakumar123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2013, 01:01 AM
  4. Update Userform Template List
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-24-2010, 07:19 AM
  5. Edit/Update list from userform (auto alphabetized)
    By Jogier505 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-07-2009, 06:28 PM

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