ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting 2 rows above a certain cell (https://www.excelbanter.com/excel-programming/400976-inserting-2-rows-above-certain-cell.html)

KDJ

Inserting 2 rows above a certain cell
 
I have a column with numbers that are sorted in ascending order e.g

1
1
1
3
3
3
7
7
7

The highest number possible is 8. I would like to insert a line above the
spot where the number changes. How can I do this?
--
Thanks very much. KDJ

Don Guillett

Inserting 2 rows above a certain cell
 
In this case, one between last 3 and first 7? Or, 3-7 and 1-3?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"KDJ" wrote in message
...
I have a column with numbers that are sorted in ascending order e.g

1
1
1
3
3
3
7
7
7

The highest number possible is 8. I would like to insert a line above the
spot where the number changes. How can I do this?
--
Thanks very much. KDJ



Bob Phillips

Inserting 2 rows above a certain cell
 
Subject is at odds with the text!

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - 1 To 1 Step -1
If .Cells(i, TEST_COLUMN).Value < .Cells(i + 1,
TEST_COLUMN).Value Then
.Rows(i + 1).Insert
End If
Next i

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"KDJ" wrote in message
...
I have a column with numbers that are sorted in ascending order e.g

1
1
1
3
3
3
7
7
7

The highest number possible is 8. I would like to insert a line above the
spot where the number changes. How can I do this?
--
Thanks very much. KDJ




KDJ

Inserting 2 rows above a certain cell
 
I realised the mistake after I posted. Sorry!! Momentary lapse of reason ...

Yes, I did mean insert 2 rows (lines) above the spot where the number
changes i.e. above the first time 3 appears and above the first time 7
appears.

Thank you!
KDJ


"Bob Phillips" wrote:

Subject is at odds with the text!

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - 1 To 1 Step -1
If .Cells(i, TEST_COLUMN).Value < .Cells(i + 1,
TEST_COLUMN).Value Then
.Rows(i + 1).Insert
End If
Next i

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"KDJ" wrote in message
...
I have a column with numbers that are sorted in ascending order e.g

1
1
1
3
3
3
7
7
7

The highest number possible is 8. I would like to insert a line above the
spot where the number changes. How can I do this?
--
Thanks very much. KDJ





Bob Phillips

Inserting 2 rows above a certain cell
 
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - 1 To 1 Step -1
If .Cells(i, TEST_COLUMN).Value < .Cells(i + 1, _
TEST_COLUMN).Value Then
.Rows(i + 1).Resize(2).Insert
End If
Next i

End With

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"KDJ" wrote in message
...
I realised the mistake after I posted. Sorry!! Momentary lapse of reason
...

Yes, I did mean insert 2 rows (lines) above the spot where the number
changes i.e. above the first time 3 appears and above the first time 7
appears.

Thank you!
KDJ


"Bob Phillips" wrote:

Subject is at odds with the text!

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow - 1 To 1 Step -1
If .Cells(i, TEST_COLUMN).Value < .Cells(i + 1,
TEST_COLUMN).Value Then
.Rows(i + 1).Insert
End If
Next i

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"KDJ" wrote in message
...
I have a column with numbers that are sorted in ascending order e.g

1
1
1
3
3
3
7
7
7

The highest number possible is 8. I would like to insert a line above
the
spot where the number changes. How can I do this?
--
Thanks very much. KDJ








All times are GMT +1. The time now is 03:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com