+ Reply to Thread
Results 1 to 5 of 5

VBA Userform Edit/Update record help

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Ahmedabad,India
    MS-Off Ver
    Excel 2007
    Posts
    12

    Post VBA Userform Edit/Update record help

    Dear Sir,

    Please find the attached file of data entry userform.

    you will find in sheet two buttons 1. Add data and 2 . Edit / Update data

    My question is that ...
    In edit/update data userform, when i click button update record then new rows create in excel it should not to be .
    only update record which sr no i selected ..

    can u help me in this vba coding .
    Attached Files Attached Files
    From :
    Sa.1985

  2. #2
    Registered User
    Join Date
    11-25-2008
    Location
    Poland
    MS-Off Ver
    MSO 2K3, 2K10
    Posts
    84

    Re: VBA Userform Edit/Update record help

    Full code in UserForm2 module:
    Option Explicit
    
    
    Private Sub ComboBox1_Change()
      If Me.ComboBox1.ListIndex < 0 Then Exit Sub
    
      With MyRange.Cells(1).Offset(ComboBox1.ListIndex)
        TextBox1.Value = .Offset(, 1).Value
        TextBox2.Value = .Offset(, 2).Value
        TextBox3.Value = .Offset(, 3).Value
        TextBox4.Value = .Offset(, 4).Value
        TextBox5.Value = .Offset(, 5).Value
        TextBox6.Value = .Offset(, 6).Value
        TextBox7.Value = .Offset(, 7).Value
        TextBox8.Value = .Offset(, 8).Value
        TextBox9.Value = .Offset(, 9).Value
        TextBox10.Value = .Offset(, 10).Value
        TextBox11.Value = .Offset(, 11).Value
        TextBox12.Value = .Offset(, 12).Value
        TextBox13.Value = .Offset(, 13).Value
        TextBox14.Value = .Offset(, 14).Value
        TextBox15.Value = .Offset(, 15).Value
        TextBox16.Value = .Offset(, 16).Value
        TextBox17.Value = .Offset(, 17).Value
        TextBox18.Value = .Offset(, 18).Value
      End With
    End Sub
    
    
    Private Sub CommandButton1_Click()
      If Me.ComboBox1.ListIndex < 0 Then Exit Sub
    
      With MyRange.Cells(1).Offset(ComboBox1.ListIndex)
    
        .Offset(, 0).Value = ComboBox1.Value
        .Offset(, 1).Value = TextBox1.Value
        .Offset(, 2).Value = TextBox2.Value
        .Offset(, 3).Value = TextBox3.Value
        .Offset(, 4).Value = TextBox4.Value
        .Offset(, 5).Value = TextBox5.Value
        .Offset(, 6).Value = TextBox6.Value
        .Offset(, 7).Value = TextBox7.Value
        .Offset(, 8).Value = TextBox8.Value
        .Offset(, 9).Value = TextBox9.Value
        .Offset(, 10).Value = TextBox10.Value
        .Offset(, 11).Value = TextBox11.Value
        .Offset(, 12).Value = TextBox12.Value
        .Offset(, 13).Value = TextBox13.Value
        .Offset(, 14).Value = TextBox14.Value
        .Offset(, 15).Value = TextBox15.Value
        .Offset(, 16).Value = TextBox16.Value
        .Offset(, 17).Value = TextBox17.Value
        .Offset(, 18).Value = TextBox18.Value
      End With
    
      Unload Me
      MsgBox "Record Updated"
    End Sub
    
    
    Private Sub CommandButton3_Click()
      Unload Me
    End Sub
    
    
    Private Sub UserForm_Initialize()
      Dim MyRng    As Range
      ComboBox1.Clear
    
      Set MyRng = MyRange
      
      If Not MyRng Is Nothing Then
        If MyRng.Count = 1 Then
          ComboBox1.AddItem MyRng.Value
        Else
          ComboBox1.List = MyRange.Value
        End If
      End If
      
    End Sub
    
    
    Function MyRange() As Range
      Dim LastRange As Range
      With Sheet1
        Set LastRange = .Cells(Rows.Count, "A").End(xlUp)
        If LastRange.Row > 2 Then
          Set MyRange = .Range(.[a3], LastRange)
        End If
      End With
    End Function
    Artik

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Ahmedabad,India
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Userform Edit/Update record help

    Thanks,
    Artik_PL

    thank you so much

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VBA Userform Edit/Update record help

    @ sa.1985

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  5. #5
    Registered User
    Join Date
    11-20-2013
    Location
    India, Chennai
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: VBA Userform Edit/Update record help

    Hello,

    I have a similar requirement to edit a record.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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