+ Reply to Thread
Results 1 to 19 of 19

Edit worksheet data thru userform

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-07-2005
    Posts
    280

    Re: Edit worksheet data thru userform

    Therefore, I think that there is a relationship between The example find code and amendment code .. but I don't know what is it exactly??!!!
    Hi,

    As I expected, There is a relationship between The searching Code and Amendment Code, which complete each other.

    Searching Code's job is looking for the concerned record (selected by ComboBox) and stops on it by (Using Select property).

    Then, Amendment code pastes the new changes to the recoded selected by Searching code.

    Anyhow, I summarized the code to fit my need.

    Private Sub ComboBox1_Change()
        
    On Error GoTo 1
    
    With MyRange.Find(ComboBox1)
       .Select
        TextBox1 = .Offset(0, 1)
    End With
    
    1 End Sub
    
    Private Sub CommandButton1_Click()
      
    With ActiveCell
        .Value = ComboBox1
        .Offset(0, 1) = TextBox1
    End With
    Unload Me
    
    End Sub
    The only problem with this code is that it works only on the database sheet .. but when we run the code from another sheet, it doesn't work at all,

    Therefore, for me the only solution for that is the trick I mentioned in My post # 14.

    Thanks for all,
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: Edit worksheet data thru userform

    Hi,

    Replace all your code with the following

    Public MyRange As Range
    Public ws As Worksheet
    Public Idx As Long
    Private Sub ComboBox1_Change()
    Idx = Me.ComboBox1.ListIndex + 1
    If Idx = 0 Then
        Me.TextBox1.Value = ""
    Else
        Me.TextBox1.Value = Application.Index(MyRange.Value, Idx, 2)
    End If
    End Sub
    
    Private Sub CommandButton1_Click()
    With MyRange.Cells(1, 1)
        If Idx = 0 Then
            Idx = Me.ComboBox1.ListCount
            .Offset(Idx).Value = Me.ComboBox1
            .Offset(Idx, 1).Value = Me.TextBox1
            Set MyRange = ws.Range("A2:B" & ws.Range("a" & Rows.Count).End(xlUp).Row)
            Me.ComboBox1.List = Application.Index(MyRange.Value, 0, 1)
        Else
            .Offset(Idx - 1).Value = Me.ComboBox1
            .Offset(Idx - 1, 1).Value = Me.TextBox1
        End If
    End With
    End Sub
    
    Private Sub CommandButton2_Click()
    Unload Me
    End Sub
    
    Private Sub UserForm_Initialize()
    Set ws = Sheets("Sheet1")
    Set MyRange = ws.Range("A2:B" & ws.Range("a" & Rows.Count).End(xlUp).Row)
    Me.ComboBox1.List = Application.Index(MyRange.Value, 0, 1)
    End Sub
    HTH
    Kris

  3. #3
    Forum Contributor
    Join Date
    11-07-2005
    Posts
    280

    Re: Edit worksheet data thru userform

    Hi,

    Thank you Krishnakumar for your reply,

    Your codes are excellent, but I am so sorry to tell you that the problem is still existing

    What is new in your codes is the following,

    If ComboBox1 value was changed, the new values are not recorded in the first row of the list like previous examples, but they are added to the worksheet list as a new record.

    Anyhow, I think the best and the most satisfactory solution for this case is creating a new Textbox and use the first one for employee name and the other one for badge number and ComboBox1 value will stay as it is without changing.

    Thank you all,
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: Edit worksheet data thru userform

    Hi,

    The problem is still existing .. the changes are still recorded in the first record.

    the new values are not recorded in the first row of the list like previous examples, ..
    I'm not sure what you are after.

    Let us know what exactly you need.

+ 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