Hi,
I am pretty new to VBA programming. I am new to programming of any kind all together. However, I am required to prepare an excel userform in which a user can select a value from the drop down combobox and the text box is linked to the corresponding column. The combobox gets its value from a database in the same sheet. Further if the value is not present, user can type the value in both the boxes. I have tried to do it myself, seeking help from various forums but m not able to do it.
Please Help me with this.
P.S. would it be possible to add the value in the data base automatically, if it is typed by the user.
Private Sub cmdclose_Click()
Unload Me
End Sub
Private Sub cmdAdd_Click()
Dim lRow As Long
Dim lmeter As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
lmeter = Me.cmboMeter.ListIndex
If Trim(Me.cmboMeter.Value) = "" Then
Me.cmboMeter.SetFocus
MsgBox "please eneter a value"
End If
Exit Sub
If Trim(Me.cmboMeter.Value) = "other.." Then
Me.txtRef_1.SetFocus
MsgBox "please enter a reference number"
Exit Sub
End If
With ws
.Cells(lRow, 1).Value = Me.cmboMeter.Value
.Cells(lRow, 2).Value = Me.txtRef_1.Value
.Cells(lRow, 3).Value = Me.units.Value
End With
Me.cmboMeter.Value = ""
Me.txtRef_1.Value = ""
Me.units.Value = ""
Me.cmboMeter.SetFocus
End Sub
Private Sub UserForm_Initialize()
Dim cmeter As Range
Dim ws As Worksheet
Set ws = Worksheets("sheet4")
Me.MultiPage1.Value = 0
For Each cmeter In ws.Range("meter1")
With Me.cmboMeter
.AddItem cmeter.Value
.List(.ListCount - 1, 1) = cmeter.Offset(0, 1).Value
End With
Next cmeter
End Sub
Private Sub txtRef_1_AfterUpdate()
Me![txtRef_1] = Me!cmboMeter.Column(1)
End Sub
Thanks.
Bookmarks