ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,731
- Office Version
- 2007
- Platform
- Windows
Here is my userform code.
The textbox called CustomerID is where the number is stored.
I enter a number & hit enter on my keyboard then the values are shown in the other textboxes.
How can i add a button on the userform so when clicked it either adds 1 to the current value or takes away 1 from the current value & load its values.
Currently im doing it all manully & its very time consuming
Thanks
The textbox called CustomerID is where the number is stored.
I enter a number & hit enter on my keyboard then the values are shown in the other textboxes.
How can i add a button on the userform so when clicked it either adds 1 to the current value or takes away 1 from the current value & load its values.
Currently im doing it all manully & its very time consuming
Thanks
Rich (BB code):
Private Sub CustomerID_AfterUpdate()
Dim id As Variant, rowcount As Integer, foundcell As Range
id = CustomerID.Value
rowcount = Sheets("G INCOME").Cells(Rows.Count, 13).End(xlUp).Row ' THIS IS COLUMN NUMBER WHERE EMP ID LOCATED
With Worksheets("G INCOME").Range("M1:M" & rowcount) ' THIS IS CELL REFERENCE OF WHERE THE TEXT EMP ID IS LOCATED
Set foundcell = .Find(what:=id, LookIn:=xlValues)
If Not foundcell Is Nothing Then
TextBox1.Value = .Cells(foundcell.Row, 2)
TextBox2.Value = .Cells(foundcell.Row, 3)
TextBox3.Value = .Cells(foundcell.Row, 4)
TextBox4.Value = .Cells(foundcell.Row, 5)
TextBox5.Value = .Cells(foundcell.Row, 6)
Else
MsgBox "CUSTOMER'S ID IS INCORRECT", vbCritical, "CUSTOMER ID IS INCORRECT MESSAGE"
End If
End With
End Sub
Private Sub TransferValues_Click()
Dim Lastrow As Long, i As Long
Dim wsGIncome As Worksheet
Dim arr(1 To 5) As Variant
Dim Prompt As String
Set wsGIncome = ThisWorkbook.Worksheets("G INCOME")
For i = 1 To UBound(arr)
arr(i) = Choose(i, TextBox1.Value, TextBox2.Value, TextBox3.Value, TextBox4.Value, TextBox5.Value)
If Len(arr(i)) = 0 Then
MsgBox "YOU MUST COMPLETE ALL THE FIELDS", vbCritical, "USERFORM FIELDS EMPTY MESSAGE"
Exit Sub
End If
Next i
Application.ScreenUpdating = False
With wsGIncome
Lastrow = .Cells(.Rows.Count, "N").End(xlUp).Row + 1
With .Cells(Lastrow, 14).Resize(, UBound(arr))
.Value = arr
.Font.Name = "Calibri"
.Font.Size = 11
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders.Weight = xlThin
.Interior.ColorIndex = 6
.Cells(1, 1).HorizontalAlignment = xlLeft
Application.ErrorCheckingOptions.BackgroundChecking = False
End With
With Sheets("G INCOME")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("N4:S" & x).Sort Key1:=Range("N4"), Order1:=xlAscending, Header:=xlGuess
End With
Unload SAMECUSTOMER
.Range("N4").Select
End With
Application.ScreenUpdating = True
End Sub