Check VBA code to locate value in cell

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello this is the current code I have

VBA Code:
Private Sub TextBox1_AfterUpdate()

Dim m As String
Dim rx As String
rx = Trim(TextBox1.Text)
lastrow = Worksheets("sheet1").Cells(rows.Count, 5).End(x1Up).Row

For i = 2 To lastrow
If Worksheets("sheet1").Cells(i, 1).Value = rx Then
TextBox2.Text = Worksheets("sheet1").Cells(i, 2).Value

If rx = (InStr(Me.TextBox1.Value, "/") > 0 Or InStr(Me.TextBox1.Value, ",") > 0) Then
m = MsgBox("Please confirm", vbYesNo, "Double Check")
        End If
    End If
End Sub

I want it such that if there is a "/" or "," along with the found value. A message box should pop out. Currently, there seems to be a error. Could you help me edit it?
 

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
More like
VBA Code:
Private Sub TextBox1_AfterUpdate()


Dim m As String
Dim rx As String
rx = Trim(TextBox1.Text)
LastRow = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
   If InStr(Me.TextBox1.Value, "/") > 0 Or InStr(Me.TextBox1.Value, ",") > 0 Then
      If MsgBox("Please confirm", vbYesNo, "Double Check") = vbNo Then Exit Sub
   End If
     
For i = 2 To LastRow

If Worksheets("sheet1").Cells(i, 5).Value = rx Then
m = MsgBox("Please confirm", vbYesNo, "Double Check")

    End If
Next
End Sub
but now the msg box don't pop up after the number match from typing in the textbox
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,895
Office Version
  1. 365
Platform
  1. Windows
Did you press yes or no on the 1st message box?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,895
Office Version
  1. 365
Platform
  1. Windows
What is in the textbox?
 

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows

ADVERTISEMENT

What is in the textbox?
My column I have 12345 / written. Then i write 12345 in the box, and no msg box pops out
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,895
Office Version
  1. 365
Platform
  1. Windows
Will the textbox always contain a number?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,895
Office Version
  1. 365
Platform
  1. Windows
In that case use
VBA Code:
rx = Val(Trim(TextBox1.Text))
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,895
Office Version
  1. 365
Platform
  1. Windows
Did you put 12345 in col A before the last row of data in col E?
 

Watch MrExcel Video

Forum statistics

Threads
1,112,799
Messages
5,542,574
Members
410,560
Latest member
1ndependent
Top