![]() |
Trapping a NO FIND after a find
I use the code below to store a row number to a variable after a find.
I would like to trap a NO FIND if the find is unsuccessfull Any ideas. FSt1 provided the code below Sub macfindrow() dim rn as string dim rng as range dim therow as long rn = inputbox("enter something to find") if rn < "" then Set rng = nothing Set rng = range("A1:IV65536").Find(what:=rn, _ After:=Range("A1"), _ Lookin:=xlformulas, _ Lookat:=xlpart, _ SearchOrder:=xlbyrows, _ SearchDirection:=xlNext, _ MatchCase:=false) end if therow = rng.row msgbox "Found at cell " & rng.address msbbox "The row number is " & therow end sub |
hi,
if nothing was found, how do you trap nothing? add this to the code before the other msgboxes. If rng Is Nothing Then MsgBox rn & " was Not found." exit sub End If regards FSt1 "Alan" wrote: I use the code below to store a row number to a variable after a find. I would like to trap a NO FIND if the find is unsuccessfull Any ideas. FSt1 provided the code below Sub macfindrow() dim rn as string dim rng as range dim therow as long rn = inputbox("enter something to find") if rn < "" then Set rng = nothing Set rng = range("A1:IV65536").Find(what:=rn, _ After:=Range("A1"), _ Lookin:=xlformulas, _ Lookat:=xlpart, _ SearchOrder:=xlbyrows, _ SearchDirection:=xlNext, _ MatchCase:=false) end if therow = rng.row msgbox "Found at cell " & rng.address msbbox "The row number is " & therow end sub |
Hello,
Thanks again. I can now go off and do something else within the script if nothing is found "FSt1" wrote: hi, if nothing was found, how do you trap nothing? add this to the code before the other msgboxes. If rng Is Nothing Then MsgBox rn & " was Not found." exit sub End If regards FSt1 "Alan" wrote: I use the code below to store a row number to a variable after a find. I would like to trap a NO FIND if the find is unsuccessfull Any ideas. FSt1 provided the code below Sub macfindrow() dim rn as string dim rng as range dim therow as long rn = inputbox("enter something to find") if rn < "" then Set rng = nothing Set rng = range("A1:IV65536").Find(what:=rn, _ After:=Range("A1"), _ Lookin:=xlformulas, _ Lookat:=xlpart, _ SearchOrder:=xlbyrows, _ SearchDirection:=xlNext, _ MatchCase:=false) end if therow = rng.row msgbox "Found at cell " & rng.address msbbox "The row number is " & therow end sub |
All times are GMT +1. The time now is 05:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com