input box if cancel.. exit sub

buzz71023

Active Member
Joined
May 29, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
I have this code below, it works well with the exception if "cancel" is clicked on the input box. It is selecting all of the shapes on the page and changes the color of them from yellow to brown. So basically it is running the rest of the code after cancel is clicked.

Thanks

What I would like is if cancel is clicked to exit sub

Code:
Sub RACKCHART_Group26_Click()

Dim myITEM As String, myRng As Range, NewLoc As String
Dim Found As Range, RackSht As Worksheet

Application.ScreenUpdating = False

Set RackSht = Sheets("Rack Chart")

'Search for Product Code or Lot Number
myITEM = InputBox("Enter what you would like to search for.", "Search", "Enter Here")

Sheets("List").Select

Set Found = Columns("C:D").Find(what:=myITEM, LookIn:=xlValues, lookat:=xlWhole)

If Found Is Nothing Then
    MsgBox ("Item " & myITEM & " could not be found.")
    RackSht.Select
    Exit Sub

Else

Application.ScreenUpdating = True

End If

Application.ScreenUpdating = False
    
Range("F" & Found.Row).Select
    
NewLoc = ActiveCell.Value

Sheets("Rack Chart").Select

Application.ScreenUpdating = True

    ActiveSheet.Shapes(NewLoc).Select

'Turn Selection YELLOW
    With Selection.ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.RGB = RGB(255, 255, 0)
            .Transparency = 0
            .Solid
    End With
        
MsgBox ("The location of your item is " & NewLoc)
        
'Turn Selection back to BROWN
        With Selection.ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.RGB = RGB(153, 102, 51)
            .Transparency = 0
            .Solid
        End With
Range("a1").Select
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
dim myItem as String
myItem = InputBox("Enter Something")

If StrPtr(myItem) = 0 Then
    MsgBox "cancel pressed"
    Exit Sub
Else
    If myItem = vbNullString Then
        MsgBox "no string entered"
    Else
        MsgBox myItem & " was entered"
    End If
End If
 
Upvote 0
Thanks for the quick reply. I am working on introducing your code now... I'll reply back with any issues.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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