+ Reply to Thread
Results 1 to 5 of 5

Insert n number of rows from a user form click event

  1. #1
    Registered User
    Join Date
    03-20-2011
    Location
    Brisbane
    MS-Off Ver
    Excel 2003
    Posts
    14

    Insert n number of rows from a user form click event

    I have a user form command button click event that starts the below sub

    Please Login or Register  to view this content.
    I want to include a control on the form that allows a user to enter a number into.

    based on the number I want the above sub to insert the same number of rows with formulas and formats.

    ie if the user enters 3 I need 3 new rows, if they enter 5 I need 5 new rows.

    I can't work out the exact coding. Would appreciate some help.

    Thanks

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Insert n number of rows from a user form click event

    Let's say you have a combo box control named ComboBox1.
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    03-20-2011
    Location
    Brisbane
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Insert n number of rows from a user form click event

    Thats brilliant,

    I had to jig it a little bit to do what I wanted but this is what I came up with and it works a treat. the actual form is to book staff travel. Sometimes there will be one person sometimes 4 or more maybe.So doing this reduces the amount of data entry and increases the data integrity.

    Took me a while to realise that if only one person was traveling -- putting 1 in the combo box created a new row, but in that case I wouldn't want one, so changing the code to read '2' fixed that.

    I still have lots of work to do, but this is another step done. Once again thanks.

    Please Login or Register  to view this content.
    One thing -- the 2 lines above 'xlPasteFormulas and xlPasteFormats' - I tried to put them into one line, but it wouldn't work. Is there a cleaner way to code that portion?

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Insert n number of rows from a user form click event

    Is there any reason you couldn't just do an ordinary paste instead of a paste special?

  5. #5
    Registered User
    Join Date
    03-20-2011
    Location
    Brisbane
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Insert n number of rows from a user form click event

    Ummm tlafferty -- not sure

    I am not that good with vba yet, when I write the line
    Please Login or Register  to view this content.
    the drop down menu only has PasteSpecial, not paste on its own. I assumed that it had to be that way.

    Please explain so that I can learn more.

    thanks

+ 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