You are here:

Excel/Creating specific number of blank rows

Advertisement


Question
Yana Sample File
Yana Sample File  
Good morning Bob,

I am trying to create a specific number of blank rows on my spreadsheet using a macro i copied from the internet. This one creates only single rows:

Sub InsertRow()
   '
   ' Keyboard Shortcut: Option+Cmd+Shift+S
   
   '
  For i = Range("D65536").End(xlUp).Row To 2 Step -14
      If Cells(i, 1).Value <> Cells(i - 1, 1).Value Then Rows(i).Insert
  Next
End Sub

What must i amend on the above macro to create a different number of rows. eg 14 each time the number changes on column D.
I need to learn where to amend on the macro itself as each time the number of rows may vary upon using different files. Thank you for your help.

Yana

Answer
this will insert a blank row wherever there's a new item in column D.
No idea wht 14 was there in the first place!

Sub InsertRow()
   '
   ' Keyboard Shortcut: Option+Cmd+Shift+S
   
   '
  For i = Range("D65536").End(xlUp).Row To 2 Step -1
      If Cells(i, 1).Value <> Cells(i - 1, 1).Value Then Rows(i).Insert
  Next
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bob Umlas

Expertise

I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/

Experience

Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Publications
Excellence, The Expert, Microsoft

Education/Credentials
BA in math, Hofstra University, 1965

Awards and Honors
MVP
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2016 About.com. All rights reserved.