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.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi akw47. It seems like your first "End if" should be moved to immediately above "End Sub". HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top