VB Add a blank row?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an easy way to add a blank row after each sub-total in a spreadsheet
using VB?

Thanks,

Sandy
 
assume the word Total in is column F

Sub Addrows()
Dim lastrow as Long, i as Long
lastrow = cells(rows.count,"F").end(xlup).row
for i = lastrow to 2 step -1
if instr(1,cells(i,"F"),"Total",vbTextCompare) then
rows(i).Insert
end if
Next
End sub
 
Tom,

I tried this and it added a line before each sub-total instead of after it.
Can you please provide the script for adding the row after?

Thanks,

Sandy
 
Sub Addrows()
Dim lastrow as Long, i as Long
lastrow = cells(rows.count,"F").end(xlup).row
for i = lastrow to 2 step -1
if instr(1,cells(i,"F"),"Total",vbTextCompare) then
rows(i + 1).Insert
end if
Next
End sub
 
rows(i).Insert
becomes
rows(i+1).Insert
Tom,

I tried this and it added a line before each sub-total instead of after it.
Can you please provide the script for adding the row after?

Thanks,

Sandy
 
You have no idea how much time this has saved me! You're the best. Thanks
and have a wonderful weekend :o)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top