where is the mistake?
If you're inserting or deleting rows, it makes the code much easier to write and
understand if you start at the bottom and work your way to the top.
I think that this does what you want:
Option Explicit
Private Sub CommandButton1_Click()
Dim i As Long
For i = 10 To 1 Step -1
If Me.Range("B" & i).Value _
< Me.Range("B" & i + 1).Value Then
Me.Rows(i + 1).Insert
End If
Next i
End Sub
I assumed that the code is associated with a commandbutton from the control
toolbox toolbar placed on the worksheet that has the data.
The Me keyword refers to that worksheet that owns the commandbutton and code.
xavi garriga wrote:
I know my programming level is low and sure the mistake is a begginers
mistake...I want to insert a row if the number in row i+1 is bigger than
number than number in row i.
The code I've written is this:
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 10
If Worksheets("sheet1").Range("B" & i).Value <
Worksheets("sheet1").Range("B" & i + 1).Value Then
Rows("i:i").Insert Shift:=xlDown
End If
Next
End Sub
I can't find the mistake, can you help me????
Thanks!
--
atrep
--
Dave Peterson
|