Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Terry Pinnell
 
Posts: n/a
Default Macro to insert blank lines

I wonder if anyone already has a macro for the following operation I
perform quite often please? I insert blank lines in a long table
whenever a particular column changes. A typical example is in a list
containing a Year column, sorted by Year. It improves readability to
add a blank line between the 1972 and 1973 sections, 1973 and
1974...etc.

--
Terry, West Sussex, UK
  #3   Report Post  
Terry Pinnell
 
Posts: n/a
Default Macro to insert blank lines

"Don Guillett" wrote:

try
Sub InsertRow()
For i = cells(rows.count,"a").End(xlUp).Row To 2 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Rows(i).Insert
End If
Next
End Sub


Thanks. Now realise how rusty I am - it's been so long since I
imported a macro (much less wrote one) that I've forgotten the very
basics!

With my target worksheet open I pasted that (renamed InserBlankRow,as
I wrote one called InsertRow many years ago) into VB Editor. What does
the macro expect by way of starting conditions? Anyway, whatever cell
or cells I selected beforehand, I got 'Compile error: Variable not
defined'.

--
Terry, West Sussex, UK
  #5   Report Post  
Terry Pinnell
 
Posts: n/a
Default Macro to insert blank lines

"Don Guillett" wrote:

Pretty straight forward.
It is not using a "selection". Assumes your data to look at is in col A. It
works from the bottom up to compare the cell above and insert a row if they
DON'T match. If not col a, change the "a" to whatever column and the
cells(i,1) to ,2 or ,3 or ??


So it doesn't matter what is highlighted when I run it?

I'm still getting that same error message, so I assume I did something
wrong when that by now unfamiliar VBA Editor window was displayed. I
pasted it into a 'Module', as you see here.
http://www.terrypin.dial.pipex.com/Images/Macro1.gif

--
Terry, West Sussex, UK


  #6   Report Post  
Terry Pinnell
 
Posts: n/a
Default Macro to insert blank lines

Terry Pinnell wrote:

"Don Guillett" wrote:

Pretty straight forward.
It is not using a "selection". Assumes your data to look at is in col A. It
works from the bottom up to compare the cell above and insert a row if they
DON'T match. If not col a, change the "a" to whatever column and the
cells(i,1) to ,2 or ,3 or ??


So it doesn't matter what is highlighted when I run it?

I'm still getting that same error message, so I assume I did something
wrong when that by now unfamiliar VBA Editor window was displayed. I
pasted it into a 'Module', as you see here.
http://www.terrypin.dial.pipex.com/Images/Macro1.gif


Success! It must have been that Option Explicit line, because after
deletion it your macro worked fine, thanks.

--
Terry, West Sussex, UK
  #7   Report Post  
Don Guillett
 
Posts: n/a
Default Macro to insert blank lines

If you use option explicit you must declare all variables which is a very
good idea but not always necessary. The really good programmers always do
it. Guess what that makes me? Anyway, thanks for the kind words.

--
Don Guillett
SalesAid Software

"Terry Pinnell" wrote in message
...
Terry Pinnell wrote:

"Don Guillett" wrote:

Pretty straight forward.
It is not using a "selection". Assumes your data to look at is in col A.

It
works from the bottom up to compare the cell above and insert a row if

they
DON'T match. If not col a, change the "a" to whatever column and the
cells(i,1) to ,2 or ,3 or ??


So it doesn't matter what is highlighted when I run it?

I'm still getting that same error message, so I assume I did something
wrong when that by now unfamiliar VBA Editor window was displayed. I
pasted it into a 'Module', as you see here.
http://www.terrypin.dial.pipex.com/Images/Macro1.gif

Success! It must have been that Option Explicit line, because after
deletion it your macro worked fine, thanks.

--
Terry, West Sussex, UK



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert date in macro George Gee New Users to Excel 12 April 17th 06 05:44 AM
Macro to copy range of formulas to equal data lines lh Excel Worksheet Functions 2 August 15th 05 04:37 PM
Delete Blank Lines Charles Excel Discussion (Misc queries) 3 August 8th 05 05:11 PM
Help: I need a macro to add words every 3 lines Mirandolle Excel Discussion (Misc queries) 11 August 7th 05 05:03 PM
Insert text in a cell with a macro kayabob Excel Discussion (Misc queries) 5 June 22nd 05 05:43 PM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"