I have a list of numbers sorted in column L from largest to smallest. I want to insert a line when the numbers switch from positive to negative. My code right now is just inserting a row wherever the cell is when I run my macro, can you tell me what I'm doing wrong?
Dim i As Long
i = 3
Do While Range("L" & i) <> ""
If checksign(Range("L" & i)) <> checksign(Range("L" & i - 1)) Then
ActiveCell.EntireRow.Insert shift:=xlDown
i = i + 1 'Shift downward after insert a row
End If
i = i + 1
Loop
End Sub
Function checksign(cells As Range) As String
' check if the sign of lastcell is different from the previous one
If cells < 0 Then
checksign = "Negative"
Else
checksign = "Positive"
End If
End Function
Dim i As Long
i = 3
Do While Range("L" & i) <> ""
If checksign(Range("L" & i)) <> checksign(Range("L" & i - 1)) Then
ActiveCell.EntireRow.Insert shift:=xlDown
i = i + 1 'Shift downward after insert a row
End If
i = i + 1
Loop
End Sub
Function checksign(cells As Range) As String
' check if the sign of lastcell is different from the previous one
If cells < 0 Then
checksign = "Negative"
Else
checksign = "Positive"
End If
End Function