Consulting

Results 1 to 2 of 2

Thread: Inserting Multiple Rows in Excel based on cell selection

  1. #1

    Inserting Multiple Rows in Excel based on cell selection

    New to the forum and new to VBA, so hello and my apologies in advance
    Not sure if this has been covered I looked but could not find a specific answer to my question, so here goes:

    I would like to insert multiple blank rows based on cells that I have selected in the spreadsheet.

    I created an ActiveX command button and entered the code below which works perfectly if I only have one cell selected. It does not work if I select more than one cell at a time.
    I would like the ability to select multiple cells in the spreadsheet (via <ctrl-left click>) and then click a command button to insert a blank row below each of those selected cells.

    Any help that you can provide would be greatly appreciated. Thanks for your time.


    • SubNewLine()
    • Dim topLine AsInteger: topLine =2'never insert before this line
    • ActiveSheet.Rows(IIf(ActiveCell.Row > topLine, _
    • ActiveCell.Row, _
    • topLine)) _
    • .EntireRow.Insert
    • End Sub

  2. #2
    VBAX Regular
    Joined
    Jan 2018
    Location
    The Netherlands
    Posts
    45
    Location
    Count the rows within the selektion, please show us what you have in a attachement.

Posting Permissions

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