![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
I'm using the following code to search for a text string, can someone help me with the code which will allow me to bring up a message box if the text string is not found.
Columns("A:A").Select Selection.Find(What:=mskBlue.Text, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate Thanks in advance Matt |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Columns("A:A").Select On Error Resume Next Selection.Find(What:=mskBlue, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate If Err Then MsgBox "nothing found" On Error GoTo 0 |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Thanks Ivan
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Ivan
Have supplied my code below, one more problem that you may be able to help me with. If my search is unsuccessful, the code the control boxes on my form still pick up the text in the activecell (which happens to be the header). Is there any code that will stop the procedure from picking up text from the activecell if the search is negative? Hope you can understand and help. Private Sub cmdFind_Click() Columns("A:A").Select On Error Resume Next Selection.Find(What:=mskBlue.Text, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate If Err Then MsgBox "nothing found" On Error GoTo 0 cboOriginator.Text = ActiveCell.Offset(0, 1) cboClient.Text = ActiveCell.Offset(0, 2) txtJobDes.Text = ActiveCell.Offset(0, 3) mskPriority.Text = ActiveCell.Offset(0, 6) mskDateIT.Text = ActiveCell.Offset(0, 11) mskDatReq.Text = ActiveCell.Offset(0, 13) mskDateBooked.Text = ActiveCell.Offset(0, 12) cboProgrammer.Text = ActiveCell.Offset(0, 7) thanks Matt |
|
|
|
|
|
#5 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Private Sub cmdFind_Click() Columns("A:A").Select On Error Resume Next Selection.Find(What:=mskBlue.Text, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate If Err Then MsgBox "nothing found":Exit Sub On Error GoTo 0 'The rest of your Code |
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Magic, thanks Ivan
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|