Hi
I have the following 2 columns. I want to assign the order no. for each client using VBA as below. There are several worksheets in the workbook. But the code doesn't work. Please help.
<colgroup><col><col></colgroup><tbody>
</tbody>
QUOTE
Sub assignnumber()
Dim lr As Long
Dim WS As Worksheet
Dim x As Long
For Each WS In Worksheets
lr = WS.Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lr
WS.Range("A2") = 1
If WS.Range("B" & x) = WS.Range("B" & x - 1) Then
WS.Range("A" & x).Value = WS.Range("A" & x - 1) + 1
End If
Next x
Next WS
End Sub
UNQUOTE
Regards
Mark
I have the following 2 columns. I want to assign the order no. for each client using VBA as below. There are several worksheets in the workbook. But the code doesn't work. Please help.
<colgroup><col><col></colgroup><tbody> </tbody> |
<colgroup><col><col></colgroup><tbody>
</tbody>
QUOTE
Sub assignnumber()
Dim lr As Long
Dim WS As Worksheet
Dim x As Long
For Each WS In Worksheets
lr = WS.Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lr
WS.Range("A2") = 1
If WS.Range("B" & x) = WS.Range("B" & x - 1) Then
WS.Range("A" & x).Value = WS.Range("A" & x - 1) + 1
End If
Next x
Next WS
End Sub
UNQUOTE
Regards
Mark