Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Auto insert of blank row depending on data

I'm trying to get myself a macro so I can analyse my data but after
running it a couple of times (and changing info) the results don't
come out as planned. Basically what I'm trying to do is get it to
insert two blank rows when a change in data happens. For example:

1
1
1
1
2
2
2

It should insert two blank rows between the 1 and 2. The problem is
that the data is not in sequence and sometimes is not a number. I need
it to recognise a change regardless of what the value is. Any help/
code would be appreciated
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Auto insert of blank row depending on data

Sub push_row()
Dim v1 As Variant, v2 As Variant
For i = 2 To Rows.Count
If IsEmpty(Cells(i, 1)) Then Exit Sub
v1 = Cells(i, 1).Value
v2 = Cells(i - 1, 1).Value
If v1 < v2 Then
Cells(i, 1).EntireRow.Insert
Cells(i, 1).EntireRow.Insert
i = i + 2
End If
Next
End Sub
--
Gary''s Student - gsnu2007b


" wrote:

I'm trying to get myself a macro so I can analyse my data but after
running it a couple of times (and changing info) the results don't
come out as planned. Basically what I'm trying to do is get it to
insert two blank rows when a change in data happens. For example:

1
1
1
1
2
2
2

It should insert two blank rows between the 1 and 2. The problem is
that the data is not in sequence and sometimes is not a number. I need
it to recognise a change regardless of what the value is. Any help/
code would be appreciated

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,480
Default Auto insert of blank row depending on data

Hi

try

Sub Insert2Rows()
Dim c As Long, lrow As Long
With ActiveSheet
lrow = .Cells(.Rows.Count, "A").End(xlUp).Row

For c = lrow - 1 To 1 Step -1
If .Cells(c, 1).Value < "" Then
If .Cells(c, "A").Value < .Cells(c + 1, "A").Value Then
.Cells(c + 1, "A").Resize(2).EntireRow.Insert
End If
End If

Next
End With

End Sub

--

Regards
Roger Govier

wrote in message
...
I'm trying to get myself a macro so I can analyse my data but after
running it a couple of times (and changing info) the results don't
come out as planned. Basically what I'm trying to do is get it to
insert two blank rows when a change in data happens. For example:

1
1
1
1
2
2
2

It should insert two blank rows between the 1 and 2. The problem is
that the data is not in sequence and sometimes is not a number. I need
it to recognise a change regardless of what the value is. Any help/
code would be appreciated


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,480
Default Auto insert of blank row depending on data

I should have added, the code assumes the values are in column A.
If not, change all instances of A"A" to whatever column letter is
applicable.

--

Regards
Roger Govier

"Roger Govier" <roger@technology4unospamdotcodotuk wrote in message
...
Hi

try

Sub Insert2Rows()
Dim c As Long, lrow As Long
With ActiveSheet
lrow = .Cells(.Rows.Count, "A").End(xlUp).Row

For c = lrow - 1 To 1 Step -1
If .Cells(c, 1).Value < "" Then
If .Cells(c, "A").Value < .Cells(c + 1, "A").Value Then
.Cells(c + 1, "A").Resize(2).EntireRow.Insert
End If
End If

Next
End With

End Sub

--

Regards
Roger Govier

wrote in message
...
I'm trying to get myself a macro so I can analyse my data but after
running it a couple of times (and changing info) the results don't
come out as planned. Basically what I'm trying to do is get it to
insert two blank rows when a change in data happens. For example:

1
1
1
1
2
2
2

It should insert two blank rows between the 1 and 2. The problem is
that the data is not in sequence and sometimes is not a number. I need
it to recognise a change regardless of what the value is. Any help/
code would be appreciated


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Auto insert of blank row depending on data

On Dec 2, 1:36 pm, "Roger Govier" <roger@technology4unospamdotcodotuk
wrote:
I should have added, the code assumes the values are in column A.
If not, change all instances of A"A" to whatever column letter is
applicable.

--

Regards
Roger Govier

"Roger Govier" <roger@technology4unospamdotcodotuk wrote in message

...

Hi


try


Sub Insert2Rows()
Dim c As Long, lrow As Long
With ActiveSheet
lrow = .Cells(.Rows.Count, "A").End(xlUp).Row


For c = lrow - 1 To 1 Step -1
If .Cells(c, 1).Value < "" Then
If .Cells(c, "A").Value < .Cells(c + 1, "A").Value Then
.Cells(c + 1, "A").Resize(2).EntireRow.Insert
End If
End If


Next
End With


End Sub


--


Regards
Roger Govier


wrote in message
...
I'm trying to get myself a macro so I can analyse my data but after
running it a couple of times (and changing info) the results don't
come out as planned. Basically what I'm trying to do is get it to
insert two blank rows when a change in data happens. For example:


1
1
1
1
2
2
2


It should insert two blank rows between the 1 and 2. The problem is
that the data is not in sequence and sometimes is not a number. I need
it to recognise a change regardless of what the value is. Any help/
code would be appreciated


Thanks all, I got it working!
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 a blank row after change in data Genghis2k3 Excel Worksheet Functions 3 January 11th 09 07:31 PM
Auto insert of blank lines Robert Excel Discussion (Misc queries) 5 November 28th 07 10:32 PM
Insert a blank row after change in data Genghis2k3 Excel Worksheet Functions 1 March 28th 07 01:09 AM
insert a blank row after data changes in a column cyndi Excel Discussion (Misc queries) 2 October 24th 05 02:46 PM
auto insert blank line Little pete Excel Discussion (Misc queries) 4 August 29th 05 09:48 PM


All times are GMT +1. The time now is 05:46 AM.

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"