albasel
06-18-2012, 10:04 PM
Good day everybody
I need to do a code to go down in a column A ,as an example, and check if the current cell value is the same with previous the counter should be increment by one else it goes and print in the next column B the value of column A + (1 up to counter). It should go until the the cell is empty.
The problem with my code that the loop becomes infinite for the first set of similar number.
Can any body help me?
Sub Macro3()
Dim pNo As Integer
Dim counter As Integer
Dim k As Integer
Dim sum As Integer
Dim num As Integer
Dim addr1 As String
Dim addr2 As String
mCounter = 1
addr1 = ActiveCell.Address
pNo = Selection.Value
Selection.Offset(1, 0).Select
Do While Selection.Value <> ""
If pNo = ActiveCell.Value Then
Selection.Offset(1, 0).Select
counter = counter + 1
Else
addr2 = ActiveCell.Offset(-1, 0).Address
Range(addr1).Select
Selection.Offset(0, 3).Select
For k = 1 To counter
Selection.Value = Range(addr1).Value & k
Selection.Offset(1, 0).Select
Next k
counter = 1
Range(addr2).Select
End If
Loop
End Sub
I need to do a code to go down in a column A ,as an example, and check if the current cell value is the same with previous the counter should be increment by one else it goes and print in the next column B the value of column A + (1 up to counter). It should go until the the cell is empty.
The problem with my code that the loop becomes infinite for the first set of similar number.
Can any body help me?
Sub Macro3()
Dim pNo As Integer
Dim counter As Integer
Dim k As Integer
Dim sum As Integer
Dim num As Integer
Dim addr1 As String
Dim addr2 As String
mCounter = 1
addr1 = ActiveCell.Address
pNo = Selection.Value
Selection.Offset(1, 0).Select
Do While Selection.Value <> ""
If pNo = ActiveCell.Value Then
Selection.Offset(1, 0).Select
counter = counter + 1
Else
addr2 = ActiveCell.Offset(-1, 0).Address
Range(addr1).Select
Selection.Offset(0, 3).Select
For k = 1 To counter
Selection.Value = Range(addr1).Value & k
Selection.Offset(1, 0).Select
Next k
counter = 1
Range(addr2).Select
End If
Loop
End Sub