Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #16  
Old 07-04-2009, 04:31 PM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Please Register to Remove these Ads

Quote:
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.

Code:
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
File Type: xls Edit data via Userform4.xls (49.0 KB, 3 views)
Reply With Quote
  #17  
Old 07-05-2009, 01:44 AM
Krishnakumar Krishnakumar is offline
Forum Contributor
 
Join Date: 19 Feb 2005
Location: Gurgaon,India
Posts: 137
Krishnakumar has been very helpful
Re: Edit worksheet data thru userform

Hi,

Replace all your code with the following

Code:
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
God's Own Country
Reply With Quote
  #18  
Old 07-05-2009, 02:23 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
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
File Type: xls Edit data via Userform5.xls (39.5 KB, 7 views)
Reply With Quote
  #19  
Old 07-06-2009, 12:06 PM
Krishnakumar Krishnakumar is offline
Forum Contributor
 
Join Date: 19 Feb 2005
Location: Gurgaon,India
Posts: 137
Krishnakumar has been very helpful
Re: Edit worksheet data thru userform

Hi,

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

Quote:
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.
__________________
Kris
God's Own Country
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump