+ Reply to Thread
Results 1 to 7 of 7

Get user input

  1. #1
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Get user input

    In the code below I need user input for the line "Do Until x = (User input as integer)". How do I do this?

    Sub InsertRow()
    '
    ' InsertRow Macro
    '
    ' Keyboard Shortcut: Ctrl+x
    '
    Dim x As Long
    x = 1
    Do Until x = 100
    Selection.EntireRow.Insert
    With Selection.Interior
    .Pattern = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Selection.Offset(2, 0).Select
    x = x + 1
    Loop
    End Sub

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Get user input

    Hi Ccpsc,

    You can include below line before "Do until.. " :_

    x = InputBox("Please provide value for x", "Input Required")


    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Get user input

    Thank you dilipandey but that asked for a number everytime it ran so I did this and it works fine. One more question how do I force the user to enter a number? At present if nothing is entered it is an infinite loop.

    Please Login or Register  to view this content.
    Last edited by ccpsc; 04-29-2012 at 03:49 PM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Get user input

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Get user input

    Cheers Roy all sorted. Can anyone answer my question above?

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Get user input

    Hi Ccpsc,

    You can put a default value in input box by editing the below line as shown:=
    Please Login or Register  to view this content.
    50 is the default value which will be there when macro runs..

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Get user input

    So where are the code tags in post #1?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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