S
Sammy
Gretings,
As part of a routine to create worksheets the following macro looks at
a list and deletes any duplicates.
The routine works great unless there is only one cell occupied in
which case I get a "Run-time error "6" overflow. Is there any way of
resolving this short of starting again. As you may have guessed my VB
skills are lacking - this code was lifted off one of the posts here
but has served me well thus far.
Sub DeleteDuplicates()
Dim X, C, xMax, y As Integer
Dim S As String
Range("A1").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
X = Selection.Cells(1).Row
xMax = Selection.Cells(Selection.Cells.Count).Row
C = Selection.Cells(1).Column
Do While X < xMax
S = ActiveSheet.Cells(X, C).Value
y = X + 1
Do While y <= xMax
If ActiveSheet.Cells(y, C).Value = S Then
ActiveSheet.Cells(y, C).Delete
xMax = xMax - 1
y = y - 1
End If
'error occurs in the following line
y = y + 1
Loop
X = X + 1
Loop
Range("A1").Select
End Sub
As part of a routine to create worksheets the following macro looks at
a list and deletes any duplicates.
The routine works great unless there is only one cell occupied in
which case I get a "Run-time error "6" overflow. Is there any way of
resolving this short of starting again. As you may have guessed my VB
skills are lacking - this code was lifted off one of the posts here
but has served me well thus far.
Sub DeleteDuplicates()
Dim X, C, xMax, y As Integer
Dim S As String
Range("A1").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
X = Selection.Cells(1).Row
xMax = Selection.Cells(Selection.Cells.Count).Row
C = Selection.Cells(1).Column
Do While X < xMax
S = ActiveSheet.Cells(X, C).Value
y = X + 1
Do While y <= xMax
If ActiveSheet.Cells(y, C).Value = S Then
ActiveSheet.Cells(y, C).Delete
xMax = xMax - 1
y = y - 1
End If
'error occurs in the following line
y = y + 1
Loop
X = X + 1
Loop
Range("A1").Select
End Sub