vba search for word and go to cell

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
471
Office Version
  1. 365
Platform
  1. Windows
Hi could someone give me a vba that would bring up a pop up box where i would type, it would then search column "A"
for the word typed from the current row +1 downwards, once word is found , it would go to cell and show popup box that word is found,
lastly once it had searched column "a" to last row it would bring up pop up box saying " complete"
Thank
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,

this will work for you:
VBA Code:
Sub test()
  Dim searchString As String, rowNumber As Long
  searchString = InputBox("Enter the word")
  With Application
  If Not IsError(.Match(searchString, Range("A:A"), 0)) Then
    rowNumber = .Match(searchString, Range("A:A"), 0)
    Range("A" & rowNumber).Select
    MsgBox "Word is found on row " & rowNumber
  End If
  MsgBox "Search Complete!"
  End With
End Sub
 
Upvote 0
thanks but once it finds example "red" on a22, it then refinds "red" on a22, as it need to search from current line plus 1
 
Upvote 0
Then:
VBA Code:
Sub test()
  Dim searchString As String, rowNumber As Long, i As Long, lRow As Long
  lRow = Cells(Rows.Count, "A").End(xlUp).Row
  searchString = InputBox("Enter the word")
  With Application
  For i = 1 To lRow
    If Not IsError(.Match(searchString, Range("A" & i  &  ":A" & lRow), 0)) Then
      rowNumber = .Match(searchString, Range("A" & i  &  ":A" & lRow), 0)
      Range("A" & rowNumber).Select
      MsgBox "Word is found on row " & rowNumber
      i = rowNumber
    End If
  Next
  MsgBox "Search Complete!"
  End With
End Sub
 
Last edited by a moderator:
Upvote 0
finds word , but then popup box when press ok reappears over and over again, had to kill excel
 
Upvote 0
What do you want?
Do you want to stop on that row, do something in excel, then continue where you left?

VBA doesn't work like that. Once you run, you have to wait until it finishes.

If this is what you want one solution can be to keep the track of where you left last time. You should reserve a cell for this. First put value 1 to B1 cell.
VBA Code:
Sub test()
  Dim searchString As String, rowNumber As Long, lRow As Long, lastValue As Long
  lRow = Cells(Rows.Count, "A").End(xlUp).Row
  searchString = InputBox("Enter the word")
  lastValue = Range("B1").Value
  With Application
    If Not IsError(.Match(searchString, Range("A" & lastValue  &  ":A" & lRow), 0)) Then
      rowNumber = .Match(searchString, Range("A" & lastValue &  ":A" & lRow), 0)
      Range("A" & rowNumber).Select
      MsgBox "Word is found on row " & rowNumber
      Range("B1").Value = rowNumber + 1
    Else
      MsgBox "Search Complete!"
    End If
  End With
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,132
Members
449,097
Latest member
mlckr

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