How to convert change event to afterupdate event

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello, was wondering why my code here
VBA Code:
Private Sub Rx2_change()
'when both value match between the 2 textbox, the rest will run
If Rx2.Value = Rx1.Value Then
    Dim rx As String
    rx = Trim(Rx2.Text)
    lastrow = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
End If

For i = 4 To lastrow
If InStr(Worksheets("sheet1").Cells(i, 8).Value, rx) Then
    With Me.Rx2
'Column 17 will add by one, whenever the value between the 2 textbox matches once
        .Tag = Val(Worksheets("sheet1").Cells(i, 17)) + 1
        TextBox2.Text = Val(.Tag)
        Worksheets("sheet1").Cells(i, 17).Value = TextBox2.Value
'if my other textbox in the userform matches with the function created on column 6, the row will change colour
        If TextBox2.Text = SumNumbersOnly(Worksheets("sheet1").Cells(i, 6)) Then
            Cells(i, 8).EntireRow.Interior.ColorIndex = 24
            .Tag = 0
        End If
'In case the value match between the textbox, happens more than the written amount
    If TextBox2.Value > TextBox13.Value Then
        MsgBox "Please recheck"
        With Me.Rx2
            .Tag = Val(Worksheets("sheet1").Cells(i, 17)) - 1
            TextBox2.Text = Val(.Tag)
            Worksheets("sheet1").Cells(i, 17).Value = TextBox2.Value
        Exit Sub

        End With
    End If
    End With
'Tried to clear all the information on the textbox on the Userform
Rx2.Value = Empty
Rx1.Value = Empty
Rx3.Value = Empty
TBName.Value = Empty
TBAddress.Value = Empty
TBTel.Value = Empty
Textbox5.Value = Empty
TextBox1.Value = Empty
Textbox6.Value = Empty
TextBox7.Value = Empty
TextBox8.Value = Empty
TextBox9.Value = Empty
TextBox10.Value = Empty
TextBox11.Value = Empty
Textbox3.Value = Empty
Textbox4.Value = Empty
TextBox12.Value = Empty
TextBox13.Value = Empty
TextBox2.Value = Empty

End If
'want to set the focus back to the original textbox Rx1.
Rx1.SetFocus
Next
End Sub

cannot work when changed to an afterupdate event? Could some help me edit it such that it can work using the afterupdate event of Rx2 textbox. Thankss excel masters.
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,676
Hi akw47. It seems like your first "End if" should be moved to immediately above "End Sub". HTH. Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,119,221
Messages
5,576,816
Members
412,748
Latest member
MikeyP14
Top