lumch
Board Regular
- Joined
- Jan 29, 2010
- Messages
- 204
Hello, I have this code (attached bellow), so I enter data in userform text, that is transfer to a excel sheet database, then when I enter in combobox data its populate according to data on database ( Sheet16 ) all names, phone numbers, insurance info, Sometimes I need to update information on data base. I have to close excel open the "view code", so is a pain, My question is How can I edit information from Userform that will change it on database (sheet 16). Thanks a lot.
Private Sub CommandButton2_Click()
On Error Resume Next
Dim iRow As Long
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
iRow = WS.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
WS.Cells(5, 2).Value = Me.TextBox1.Value
WS.Cells(5, 8).Value = Me.TextBox2.Value
WS.Cells(9, 2).Value = Me.ComboBox15.Value
WS.Cells(13, 5).Value = Me.TextBox5.Value
WS.Cells(13, 9).Value = Me.TextBox6.Value
WS.Cells(15, 9).Value = Me.TextBox7.Value
WS.Cells(15, 2).Value = Me.TextBox8.Value
WS.Cells(7, 8).Value = Me.TextBox17.Value
WS.Cells(27, 2).Value = Me.ComboBox16.Value
WS.Cells(13, 2).Value = Me.TextBox19.Value
WS.Cells(5, 9).Value = Me.TextBox22.Value
WS.Cells(8, 8).Value = Me.TextBox21.Value
WS.Cells(5, 10).Value = Me.TextBox23.Value
WS.Cells(21, 2).Value = Me.ComboBox3.Value
WS.Cells(23, 7).Value = Me.ComboBox4.Value
WS.Cells(25, 2).Value = Me.ComboBox5.Value
WS.Cells(1, 1).Value = Me.TextBox29.Value
WS.Cells(7, 2).Value = Me.TextBox32.Value
On Error Resume Next
Dim strDataRange As Range
Dim keyRange As Range
Set strDataRange = Range("A1:h5000")
Set keyRange = Range("A1:h5000")
strDataRange.Sort Key1:=keyRange, Header:=xlYes
Dim tr As Worksheet
Set tr = Worksheets("Sheet16")
iRow = tr.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
tr.Cells(iRow, 1).Value = Me.TextBox1.Value
tr.Cells(iRow, 2).Value = Me.TextBox2.Value
tr.Cells(iRow, 3).Value = Me.TextBox22.Value
tr.Cells(iRow, 4).Value = Me.TextBox23.Value
tr.Cells(iRow, 5).Value = Me.TextBox17.Value
tr.Cells(iRow, 6).Value = Me.ComboBox15.Value
tr.Cells(iRow, 7).Value = Me.TextBox21.Value
tr.Cells(iRow, 8).Value = Me.TextBox32.Value
Dim fromRow As Integer
Dim toRow As Integer
fromRow = 1
toRow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Rows(fromRow & ":" & toRow).Sort Key1: ActiveSheet.Range ("A:G"), _
Order1:=x1Ascending, Header:=x1Yes, OrderCustom:=1, _
MatchCase:=False, Orientation:=x1TopBottom
Worksheets("Sheet16").Range("A1:G50000").RemoveDuplicates Columns:=Array(1, 7), Header:=xlYes
---------------------------------------------------------------------------------------------------
THIS IS THE COMBO BOX THAT PULLS DATA FROM SHEET 16 AND POPULATES TO OTHER TEXTBOX, THANKS
Private Sub ComboBox13_Change()
On Error Resume Next
Me.TextBox1.Value = Me.ComboBox13.Column(0)
Me.TextBox2.Value = Me.ComboBox13.Column(1)
Me.TextBox22.Value = Me.ComboBox13.Column(2)
Me.TextBox23.Value = Me.ComboBox13.Column(3)
Me.TextBox17.Value = Me.ComboBox13.Column(4)
Me.ComboBox15.Value = Me.ComboBox13.Column(5)
Me.TextBox21.Value = Me.ComboBox13.Column(6)
Me.TextBox32.Value = Me.ComboBox13.Column(7)
On Error GoTo 0
End Sub
Private Sub CommandButton2_Click()
On Error Resume Next
Dim iRow As Long
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
iRow = WS.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
WS.Cells(5, 2).Value = Me.TextBox1.Value
WS.Cells(5, 8).Value = Me.TextBox2.Value
WS.Cells(9, 2).Value = Me.ComboBox15.Value
WS.Cells(13, 5).Value = Me.TextBox5.Value
WS.Cells(13, 9).Value = Me.TextBox6.Value
WS.Cells(15, 9).Value = Me.TextBox7.Value
WS.Cells(15, 2).Value = Me.TextBox8.Value
WS.Cells(7, 8).Value = Me.TextBox17.Value
WS.Cells(27, 2).Value = Me.ComboBox16.Value
WS.Cells(13, 2).Value = Me.TextBox19.Value
WS.Cells(5, 9).Value = Me.TextBox22.Value
WS.Cells(8, 8).Value = Me.TextBox21.Value
WS.Cells(5, 10).Value = Me.TextBox23.Value
WS.Cells(21, 2).Value = Me.ComboBox3.Value
WS.Cells(23, 7).Value = Me.ComboBox4.Value
WS.Cells(25, 2).Value = Me.ComboBox5.Value
WS.Cells(1, 1).Value = Me.TextBox29.Value
WS.Cells(7, 2).Value = Me.TextBox32.Value
On Error Resume Next
Dim strDataRange As Range
Dim keyRange As Range
Set strDataRange = Range("A1:h5000")
Set keyRange = Range("A1:h5000")
strDataRange.Sort Key1:=keyRange, Header:=xlYes
Dim tr As Worksheet
Set tr = Worksheets("Sheet16")
iRow = tr.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
tr.Cells(iRow, 1).Value = Me.TextBox1.Value
tr.Cells(iRow, 2).Value = Me.TextBox2.Value
tr.Cells(iRow, 3).Value = Me.TextBox22.Value
tr.Cells(iRow, 4).Value = Me.TextBox23.Value
tr.Cells(iRow, 5).Value = Me.TextBox17.Value
tr.Cells(iRow, 6).Value = Me.ComboBox15.Value
tr.Cells(iRow, 7).Value = Me.TextBox21.Value
tr.Cells(iRow, 8).Value = Me.TextBox32.Value
Dim fromRow As Integer
Dim toRow As Integer
fromRow = 1
toRow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Rows(fromRow & ":" & toRow).Sort Key1: ActiveSheet.Range ("A:G"), _
Order1:=x1Ascending, Header:=x1Yes, OrderCustom:=1, _
MatchCase:=False, Orientation:=x1TopBottom
Worksheets("Sheet16").Range("A1:G50000").RemoveDuplicates Columns:=Array(1, 7), Header:=xlYes
---------------------------------------------------------------------------------------------------
THIS IS THE COMBO BOX THAT PULLS DATA FROM SHEET 16 AND POPULATES TO OTHER TEXTBOX, THANKS
Private Sub ComboBox13_Change()
On Error Resume Next
Me.TextBox1.Value = Me.ComboBox13.Column(0)
Me.TextBox2.Value = Me.ComboBox13.Column(1)
Me.TextBox22.Value = Me.ComboBox13.Column(2)
Me.TextBox23.Value = Me.ComboBox13.Column(3)
Me.TextBox17.Value = Me.ComboBox13.Column(4)
Me.ComboBox15.Value = Me.ComboBox13.Column(5)
Me.TextBox21.Value = Me.ComboBox13.Column(6)
Me.TextBox32.Value = Me.ComboBox13.Column(7)
On Error GoTo 0
End Sub