+ Reply to Thread
Results 1 to 5 of 5

Problem with CANCEL button, INPUT BOX

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Problem with CANCEL button, INPUT BOX

    Hi,
    I need that when input box is not being filled in, the macro (new_hyperlink_from_userform) would be terminated.
    I've tried some methods to do this, below is one, but Excel still prints "FALSE" in the last row + 1 of column A.
    Any idea why?


    Option Explicit
    
    Public Sub new_hyperlink_from_userform() 'adding new hyperlinks
        With Worksheets("hyperlinks")
        
        Dim last_row As Integer, company_name As String, company_hyperlink As String
        
        last_row = .UsedRange.Rows.Count + 1
        
        company_name = Application.InputBox("Company name?")
        company_hyperlink = Application.InputBox("Company's website hyperlink?")
        
            Select Case company_name
            
                Case ""
                     .Range("a" & last_row).Clear
                    
                Case Is <> ""
                    .Range("a" & last_row).Value = company_name
                    
            End Select
                
        End With
    End Sub
    Please * if you like the answer

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem with CANCEL button, INPUT BOX

    Try this.
      company_name = Application.InputBox("Company name?")
    
      If company_name = "False" Then Exit Sub
    If posting code please use code tags, see here.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Problem with CANCEL button, INPUT BOX

    Hi, GIS2013,

    or
    Public Sub new_hyperlink_from_userform() 'adding new hyperlinks
    Dim last_row As Integer, company_name As String, company_hyperlink As String
    With Worksheets("hyperlinks")
        last_row = .UsedRange.Rows.Count + 1
        
        company_name = Application.InputBox("Company name?")
        company_hyperlink = Application.InputBox("Company's website hyperlink?")
        
        Select Case company_name
            Case False
    '             .Range("a" & last_row).Clear
            
            Case Else
                .Range("a" & last_row).Value = company_name
        
        End Select
    
    End With
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: Problem with CANCEL button, INPUT BOX

    Many thanks Holger

  5. #5
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: Problem with CANCEL button, INPUT BOX

    Thanks Norie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. InputBox OK and Cancel Button Problem
    By mackypogi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-26-2014, 07:51 PM
  2. [SOLVED] Input box and the cancel button
    By Saturn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2014, 01:21 PM
  3. [SOLVED] Input Box must be integer, Cancel button type mismatch
    By Nrowell92 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-30-2012, 03:29 PM
  4. Cancelling an inputbox if blank input or cancel button is pressed
    By kathhying in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2011, 12:07 PM
  5. Cancel button on input box causes crash
    By EGR2317 in forum Excel General
    Replies: 8
    Last Post: 06-04-2010, 09:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1