Cells Jump

  • Thread starter Thread starter jimicl
  • Start date Start date
J

jimicl

hi,

Well, Greeting from Chile, in this moment i've been working in a
macro that insert a row when a series of number in ascendent order,:
macro
ex: 1 1
1 1
1 1
2
3 2
4
4 3
5
4
4

5

but i have some problems with the result:

1)it does an endless loop
2)and it does something like this:


1
1

2
3

4
4

3) it doesn't work with numbers over 8 digits

What's wrong?



here's the macro


C = 4
D = 5
E = "1"
Do While E <> " "
Cells(C, 2).Select
A = ActiveCell.FormulaR1C1
Cells(D, 2).Select
B = ActiveCell.FormulaR1C1
Do While A = B

Cells(C, 2).Select
A = ActiveCell.FormulaR1C1
Cells(D, 2).Select
B = ActiveCell.FormulaR1C1
C = C + 1
D = D + 1

Loop

If B > A Then
Selection.EntireRow.Insert
C = C + 2
D = D + 2

Else

E = " "

End If

Loop



End Sub


Someone can help me!

thank u



JIMICL
 
try this
Sub InsertRows()
Dim myrow As Long
lastrow = Cells(65536, 1).End(xlUp).Row
For myrow = lastrow To 2 Step -1
If Cells(myrow, 1) <> Cells(myrow, 1).Offset(-1) Then _
Cells(myrow, 1).Rows.Insert
Next myrow
End Sub


--
Don Guillett
SalesAid Software
(e-mail address removed)
jimicl said:
hi,

Well, Greeting from Chile, in this moment i've been working in a
macro that insert a row when a series of number in ascendent order,:
macro
ex: 1 1
1 1
1 1
2
3 2
4
4 3
5
4
4

5

but i have some problems with the result:

1)it does an endless loop
2)and it does something like this:


1
1

2
3

4
4

3) it doesn't work with numbers over 8 digits

What's wrong?



here's the macro


C = 4
D = 5
E = "1"
Do While E <> " "
Cells(C, 2).Select
A = ActiveCell.FormulaR1C1
Cells(D, 2).Select
B = ActiveCell.FormulaR1C1
Do While A = B

Cells(C, 2).Select
A = ActiveCell.FormulaR1C1
Cells(D, 2).Select
B = ActiveCell.FormulaR1C1
C = C + 1
D = D + 1

Loop

If B > A Then
Selection.EntireRow.Insert
C = C + 2
D = D + 2

Else

E = " "

End If

Loop



End Sub


Someone can help me!

thank u



JIMICL


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
OP came back asking for modification. Gave this.
Uses column B and inserts an entire row.

Sub InsertRows()
Dim myrow As Long
lastrow = Cells(65536, "b").End(xlUp).Row
For myrow = lastrow To 2 Step -1
If Cells(myrow, "B") <> Cells(myrow, "B").Offset(-1) Then _
Cells(myrow, "B").EntireRow.Insert
Next myrow
End Sub
 
Back
Top