Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Insert a blank row after change in data | Excel Worksheet Functions | |||
Auto insert of blank lines | Excel Discussion (Misc queries) | |||
Insert a blank row after change in data | Excel Worksheet Functions | |||
insert a blank row after data changes in a column | Excel Discussion (Misc queries) | |||
auto insert blank line | Excel Discussion (Misc queries) |