View Full Version : Inserting Multiple Rows in Excel based on cell selection

08-03-2018, 02:47 AM
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.

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

08-03-2018, 03:51 AM
Count the rows within the selektion, please show us what you have in a attachement.