help regarding loops

Hi

I am just starting to learn VBA, i have attached a excel sheet and there is some data in column A and i want it like in column B. I tried it with loops, array and select case but didn't got success. Please help me.

Thanks,
Manish

AttachmentSize
my sheet.xlsx8.33 KB
Nick's picture

using VBA: 1st - insert a

using VBA:

1st - insert a row at the top..

then use this code:

Sub AddNumbers()
 
iRow = 2
iCounter = 1
 
While Cells(iRow, 1) <> ""
 
Cells(iRow, 2) = Cells(iRow, 1) & "-" & iCounter
If Cells(iRow, 1) = Cells(iRow + 1, 1) Then
 iCounter = iCounter + 1
Else
 iCounter = 1
End If
 
iRow = iRow + 1
Wend
End Sub

many Thanks

Hi Nick

Many thanks for your help. this code do exactly what i need.
once again Thank you.