Correctly Cancel or close Input Box to exit sub

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I'm attempting to have the Cancel Button or Close Button on the input box to exit the sub, can anyone assist in executing that correctly?
VBA Code:
Sub openurl()

Dim EdgeLocation As String
Dim MyURL As String
Dim i As Integer
Dim ws1 As Worksheet
Dim lastRow As Long
Dim inputValue As Variant ' n


range("A1").Select

lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

Set ws1 = Sheets("Page1_1")

EdgeLocation = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" 'Location of Edge.exe in your PC

For i = 1 To lastRow

    ' Copy the adjacent value in column CM
    Dim valueToCopy As String
    valueToCopy = ActiveSheet.range("CL" & i).Value
    ActiveSheet.range("CL" & i).Copy

   '  ActiveSheet.range("CL" & i).EntireRow.Interior.Color = RGB(0, 255, 0)

MyURL = ws1.Cells(i, 1)
    Shell (EdgeLocation & " -url -newtab " & MyURL)
    
    
     ActiveSheet.range("CN" & i) = InputBox("Enter Y or N for POD", "InputBox Example")
         If inputValue = "" Then
        End
    Else
        ' Do something with the input value
    End If
     
            range("CN1").Select
    ActiveCell.FormulaR1C1 = "POD"
    
    
    

Next i


End Sub
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Check this:

VBA Code:
Sub test_inputbox()
  Dim inputValue   As String
  inputvalue = InputBox("Enter Y or N for POD", "InputBox Example")
  If StrPtr(inputValue) = 0 Then
    MsgBox "Click Cancel, exit now"
    Exit Sub
  ElseIf Len(inputValue) = 0 Then
    MsgBox "Please Enter Y or N"
  Else
    Select Case UCase(inputValue)
      Case "Y"
        'Your code in case Y
      Case "N"
        'Your code in case N
      Case Else
        MsgBox "Please enter: Y or N"
    End Select
  End If
End Sub

Or this:

VBA Code:
Sub test_vbyesno()
  Dim inputvalue As VbMsgBoxResult
  inputvalue = MsgBox("Enter Yes or No for POD", vbQuestion + vbYesNo, "InputBox Example")
  If inputvalue = vbYes Then
    'Your code in case Y
  Else
    'Your code in case N
  End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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