+ Reply to Thread
Results 1 to 6 of 6

Insert rows for multiple selected rows

  1. #1
    Registered User
    Join Date
    05-24-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    3

    Insert rows for multiple selected rows

    Hello all,

    Can someone modify this code? It does not insert the specified rows in the input box for each selected row, just for one.

    Please Login or Register  to view this content.
    Best,
    JN
    Last edited by jeffreybrown; 05-25-2018 at 05:06 PM. Reason: Please use code tags

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Insert rows for multiple selected rows

    Quote Originally Posted by JN12345 View Post
    1. ... for each selected row ...
    2. Dim rowcount As Integer
    3. zeilenanzahl = InputBox ...
    4. Cancel = True
    1. Do you want to insert rows in the selected range, or starting from the active cell ? These are two different things.
    If you select the range from "A4" to "A1" the active cell will be "A4", if from "A1" to "A4" the active cell will be "A1".
    2. Where is "rowcount" calculated ? No calculations.
    3. Where is the "zeilenanzahl" declaration and what for is it ?
    4. Where is it from ?

    Try:
    (rows will be inserted starting from the active cell - two variants)
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-24-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    3

    Re: Insert rows for multiple selected rows

    Hello Porucha,

    Thank you for your reply. I really appreciate it. I'll try your code asap.

    Unfortunately, when I translated the code I made a typo, sorry for that. The code looks actually like this:

    Please Login or Register  to view this content.
    This code inserts the specified amount of rows after a selected cell. It works perfectly fine. However, I need a bit something else.
    1. I would like to select several cells in column A at the same time (strg + select). Those cells can be anywhere in column A, e.g. A21, A34, A45 and so on
    2. After selecting the cells I would like to insert after each selected cell a specific amount of rows. The number of rows I would put into the message box. As mentioned before, with the code above I can only insert rows after one selected cell, which would make my doing very time consuming. I read that "activecell" can only be just one row. But is there a workaround?

    Let me know if you need further clarifications.

    Best,
    JN
    Last edited by JN12345; 05-24-2018 at 04:59 PM. Reason: Typo

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Insert rows for multiple selected rows

    Quote Originally Posted by JN12345 View Post
    Please Login or Register  to view this content.
    1b. ... to select several cells ... at the same time ...
    2. After selecting the cells... to insert after ... selected cell a specific amount of rows ...
    1a,b.
    How do you want to do this with this procedure ?
    If you select some cells, two ... three ... four cells etc. and then you double-click, then you haven't multiple-selected cells but only one-selected cell, the one you double click. One action excludes this other action.

    2. Inserting rows starting from the first cell under the active cell:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-24-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    3

    Re: Insert rows for multiple selected rows

    Ok, thank you. I understand that it only works with one selected cell. But is there a workaround to insert the cells right after all selected cells?

    In the example below I would like to insert the rows I specified in the input box for all highlighted cells and not only for "UT20". Is this possible with vba?

    Untitled.png

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Insert rows for multiple selected rows

    Using the menu from the right mouse button:

    1. ThisWorkbook module
    Please Login or Register  to view this content.
    2. Standard module, Module1:
    Please Login or Register  to view this content.
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Insert a value into a certain column of selected rows
    By machinerydlr in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-25-2017, 08:18 PM
  2. Insert multiple rows each specific number of rows
    By salmasaied in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-24-2016, 09:58 AM
  3. [SOLVED] Insert multiple rows each specific number of rows
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 05-21-2016, 10:36 AM
  4. Return indexes of rows when multiple rows of a table are selected.
    By samkumar in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 08-12-2013, 04:54 AM
  5. Code to insert rows between selected cells
    By DeepakS in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2013, 08:18 AM
  6. Replies: 0
    Last Post: 03-06-2013, 05:44 PM
  7. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM

Tags for this Thread

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