Consulting

Results 1 to 6 of 6

Thread: Why would scrolling cause Application.InputBox "Cancel" behavior?

  1. #1

    Why would scrolling cause Application.InputBox "Cancel" behavior?

    Any thoughts on why this section of code would always branch to the "Is Nothing" branch simply because the user scrolled?

    Basically, if there is any scrolling of any kind (scroll wheel, scroll bar, page-up/down), the dialog appears to continue normally (i.e. it allows the user to click on a cell, reflects that cell's address in the box, etc.), but then ALWAYS results in the InputBox's "cancel" behavior.

    It works properly if no scrolling is done.

    I have found a couple of other complaints about this, but only in obscure locations and always without an answer.

    [vba]
    On Error Resume Next
    Set rngShopOrderToMove = Application.InputBox(sMessage1, gsAPPNAME, _
    Default:=rngCurrentRowShopOrder.Address, Type:=8)
    On Error GoTo MoveShopOrder_Error
    If rngShopOrderToMove Is Nothing Then
    MsgBox "Operation Cancelled"
    GoTo ErrorExit
    Else
    Set rngShopOrderToMove = wksSheet.Cells(rngShopOrderToMove.Row, _
    glSCHED_SO_COL)
    End If

    [/vba]

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    When it cancels, are you able to select a range on the sheet?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    It doesn't cancel, exactly. It acts like it's working but then when you click on OK it cancels. So you can select a cell and click OK. It just acts like you clicked Cancel if there was any scrolling involved before that.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Is there any code in the sheet module?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Does this code behave the same way on the sheet?
    [VBA]Option Explicit
    Sub selectRange()
    Dim rng As Range
    On Error Resume Next
    Set rng = Application.InputBox("Select the target range with the mouse", Type:=8)
    If rng Is Nothing Then Exit Sub
    On Error GoTo 0
    rng.Value = 2
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    If I add the line to Set rngCurrentRowShopOrder = something, .Input seems to work as expected


    [vba]
    Option Explicit

    Const sMessage1 As String = "Test"
    Const gsAPPNAME As String = "Test App"
    Const glSCHED_SO_COL As Long = 2

    Sub drv()
    Dim rngCurrentRowShopOrder As Range
    Dim rngShopOrderToMove As Range
    Dim wksSheet As Worksheet

    Set wksSheet = ActiveSheet

    'added line - no .Address if rngCurrentRowShopOrder not Set
    Set rngCurrentRowShopOrder = wksSheet.Rows(1)

    On Error Resume Next
    Set rngShopOrderToMove = Application.InputBox(sMessage1, gsAPPNAME, _
    Default:=rngCurrentRowShopOrder.Address, Type:=8)
    On Error GoTo MoveShopOrder_Error
    If rngShopOrderToMove Is Nothing Then
    MsgBox "Operation Cancelled"
    GoTo ErrorExit
    Else
    Set rngShopOrderToMove = wksSheet.Cells(rngShopOrderToMove.Row, _
    glSCHED_SO_COL)
    End If

    MoveShopOrder_Error:
    ErrorExit:
    End Sub
    [/vba]

    Paul

Posting Permissions

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