BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
Hello, I am running the following macro, which is almost running correctly now...
In an ideal world, the remaining code would then run (which would search the range for that string entered in step 1, and do the remaining steps.
I had to add the capability for the user to cancel the sub at any time, thus the "If application.inputbox = "" then" lines...
But I keep getting a "Run-time error 13: Type Mismatch" when I try and run the code. Here is the code itself...
Before I added the cancel options, the code was working fine, UNLESS the user selected cancel, in which case it was going to debug mode, which is why I needed to add the ability for my users to cancel.
Can anyone point me in the right direction on why this isn't working? If I can just get this last step done, I should be good to go...
- User enters a string in the first application.inputbox (working correctly)
- OR the user can click cancel and the sub will exit (working correctly)
- User selects range via second application.inputbox (NOT workinng)
In an ideal world, the remaining code would then run (which would search the range for that string entered in step 1, and do the remaining steps.
I had to add the capability for the user to cancel the sub at any time, thus the "If application.inputbox = "" then" lines...
But I keep getting a "Run-time error 13: Type Mismatch" when I try and run the code. Here is the code itself...
Code:
Sub SISearch(control As IRibbonControl)Dim r As Range
sTerm = Application.InputBox(prompt:="Enter text to search for", Title:="SEARCH TEXT", Type:=2)
If sTerm = "" Then
Exit Sub
Else
Set rAll = Application.InputBox(prompt:="Select range to search", Title:="RANGE SELECTION", Type:=8)
If rAll = "" Then [COLOR=#ff0000]<---[/COLOR] [COLOR=#ff0000]THIS IS WHERE MY CODE KEEPS ERRORING OUT[/COLOR]
Exit Sub
Else
For Each r In rAll
If InStr(UCase(r), UCase(sTerm)) Then
r.Offset(0, 1) = "Text located"
End If
Next r
End If
End If
End Sub
Before I added the cancel options, the code was working fine, UNLESS the user selected cancel, in which case it was going to debug mode, which is why I needed to add the ability for my users to cancel.
Can anyone point me in the right direction on why this isn't working? If I can just get this last step done, I should be good to go...
Last edited: