N
Niko
Hi everybody,
I made a small VB procedure in Excel. It controls a list of 12 cells
containing numbers. It sees to it that no duplicate numbers can be in the
list: if the user inserts a number that is already there, the previous
number is reased.
The procedure works ok. But I am sure that it can be made a little more
simple, for instance by using a FOR loop or perhaps a FOR EACH loop.
Does anybody know how?
This is the listing:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Application.EnableEvents = False
v = Target.Value
r = Target.Row
If Range("c8").Row <> r And Range("c8").Value = v Then Range("c8").Value
= ""
If Range("c9").Row <> r And Range("c9").Value = v Then Range("c9").Value
= ""
If Range("c10").Row <> r And Range("c10").Value = v Then
Range("c10").Value = ""
If Range("c11").Row <> r And Range("c11").Value = v Then
Range("c11").Value = ""
If Range("c12").Row <> r And Range("c12").Value = v Then
Range("c12").Value = ""
If Range("c13").Row <> r And Range("c13").Value = v Then
Range("c13").Value = ""
If Range("c14").Row <> r And Range("c14").Value = v Then
Range("c14").Value = ""
If Range("c15").Row <> r And Range("c15").Value = v Then
Range("c15").Value = ""
If Range("c16").Row <> r And Range("c16").Value = v Then
Range("c16").Value = ""
If Range("c17").Row <> r And Range("c17").Value = v Then
Range("c17").Value = ""
If Range("c18").Row <> r And Range("c18").Value = v Then
Range("c18").Value = ""
If Range("c19").Row <> r And Range("c19").Value = v Then
Range("c19").Value = ""
Application.EnableEvents = True
End If
End Sub
Thanks!
Niko
I made a small VB procedure in Excel. It controls a list of 12 cells
containing numbers. It sees to it that no duplicate numbers can be in the
list: if the user inserts a number that is already there, the previous
number is reased.
The procedure works ok. But I am sure that it can be made a little more
simple, for instance by using a FOR loop or perhaps a FOR EACH loop.
Does anybody know how?
This is the listing:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Application.EnableEvents = False
v = Target.Value
r = Target.Row
If Range("c8").Row <> r And Range("c8").Value = v Then Range("c8").Value
= ""
If Range("c9").Row <> r And Range("c9").Value = v Then Range("c9").Value
= ""
If Range("c10").Row <> r And Range("c10").Value = v Then
Range("c10").Value = ""
If Range("c11").Row <> r And Range("c11").Value = v Then
Range("c11").Value = ""
If Range("c12").Row <> r And Range("c12").Value = v Then
Range("c12").Value = ""
If Range("c13").Row <> r And Range("c13").Value = v Then
Range("c13").Value = ""
If Range("c14").Row <> r And Range("c14").Value = v Then
Range("c14").Value = ""
If Range("c15").Row <> r And Range("c15").Value = v Then
Range("c15").Value = ""
If Range("c16").Row <> r And Range("c16").Value = v Then
Range("c16").Value = ""
If Range("c17").Row <> r And Range("c17").Value = v Then
Range("c17").Value = ""
If Range("c18").Row <> r And Range("c18").Value = v Then
Range("c18").Value = ""
If Range("c19").Row <> r And Range("c19").Value = v Then
Range("c19").Value = ""
Application.EnableEvents = True
End If
End Sub
Thanks!
Niko