Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Vancouver, Canada
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    User Input inside a macro (2000 SR1)

    I'm writing a macro where I need the user to start in a certain cell in the spreadsheet in order for the macro to run properly. I would like a message box to come up asking them if they are in that cell and then if they say Yes, the macro will run, if they say No the macro will halt. I've tried writing it (see below) but no matter what button (Yes or No) I click, the macro will not run...I just get my msgbox that says "Put the cursor in this cell". What am I missing?

    Thanks in advance,

    Christa
    Sub Detail()
    Dim Position As Integer
    Dim Reponse As Integer
    Dim MyString As String
    Application.ScreenUpdating = False
    Reponse = MsgBox("Is the cursor in the first cell that contains a GL formula?", _
    vbYesNo + vbCritical + vbDefaultButton1, "GL Formula")
    If Response = vbYes Then
    MyString = "Yes"
    Values = ActiveCell.Value
    Position = 1
    Do Until Values = ""
    If Values = 0 Then
    ActiveCell.Offset(0, -3).Select
    Selection.Resize(Selection.Columns.Count, 4).Select
    With Selection.Font
    .FontStyle = "Bold"
    End With
    ActiveCell.Offset(1, 3).Select
    Values = ActiveCell.Value
    Else
    DrillResult
    ExpandVertical
    Values = ActiveCell.Value
    End If
    Loop
    Application.CutCopyMode = False
    Else
    MyString = "No"
    MsgBox ("Please move cursor to the first cell containing a GL Formula")
    End If
    End Sub

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Input inside a macro (2000 SR1)

    You mispelled the variable name Response in the MsgBox line. This works:

    <pre>Sub Detail()
    Dim Position As Integer
    Dim Reponse As Integer
    Dim MyString As String
    Application.ScreenUpdating = False
    Response = MsgBox("Is the cursor in the first cell that contains a GL formula?", _
    vbYesNo + vbCritical + vbDefaultButton1, "GL Formula")
    If Response = vbYes Then
    MyString = "Yes"
    Values = ActiveCell.Value
    Position = 1
    Do Until Values = ""
    If Values = 0 Then
    ActiveCell.Offset(0, -3).Select
    Selection.Resize(Selection.Columns.Count, 4).Select
    With Selection.Font
    .FontStyle = "Bold"
    End With
    ActiveCell.Offset(1, 3).Select
    Values = ActiveCell.Value
    Else
    DrillResult
    ExpandVertical
    Values = ActiveCell.Value
    End If
    Loop
    Application.CutCopyMode = False
    Else
    MyString = "No"
    MsgBox ("Please move cursor to the first cell containing a GL Formula")
    End If
    End Sub
    </pre>

    Legare Coleman

  3. #3
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Vancouver, Canada
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Input inside a macro (2000 SR1)

    Ooops...Thanks for you help!

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Input inside a macro (2000 SR1)

    Actually, it's also misspelt in the declaration (Dim Reponse as Integer).

    I find it a good idea to use the "Option Explicit", which can help to find that sort of error.
    In VBE, set "Tools, Options, require variable declaration" checked. That will put the "Option Explicit" in all new modules- but not in existing ones.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

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