Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Inputbox

  1. #1
    Board Regular Ampleford's Avatar
    Join Date
    Mar 2002
    Location
    Scotland
    Posts
    369
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have an inputbox which asks for some info, drops that on a spread then prints the spread based on that info. All well - except when you press the "Cancel" button - it still runs the Macro... What is the syntax to make it stop ?

    My script for the macro so far is :-

    Prdno = InputBox("Please enter the Period you wish to print", "Enter Period")
    Sheets("Register").Select
    Range("A1:C1").Select
    ActiveWorkbook.Unprotect
    Sheets("Data").Visible = True
    Sheets("Data").Select
    Range("e1").Select
    Selection.FormulaR1C1 = Prdno
    Sheets("Register").Select
    Range("D1:E1").Select
    ActiveCell.FormulaR1C1 = "=Data!RC[2]"~~~~~~~~~ Etc

    I know there needs to be a line after the first which acknowledges and actions the "Cancel" button...

    Help please ?


  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    If cancel is pressed a zero-length string is returned, so just add the line below after calling your inputbox: -

    Prdno = InputBox("Please enter the Period you wish to print", "Enter Period")
    If Prdno="" Then Exit Sub
    ' Rest of macro

  3. #3
    Board Regular Ampleford's Avatar
    Join Date
    Mar 2002
    Location
    Scotland
    Posts
    369
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Many Thanks


Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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