I have a small problem that I hope you can guide me, it turns out that I have to store an array and for each data that I am storing, check if it has not been entered previously, the difficulty I have is that at the beginning I define an array of 10 elements, but it can that the user needs to enter 15, 20, 30 or elements. I have tried to use the ReDim statement but I have not been able to do it since I get the error of The array already has dimensions
Attached code if you can guide me.
Sub buscarClaves()
Dim AClaves(10) As String
Dim cont As Integer
cont = 0
ReDim Preserve AClaves(cont)
Dim nClave As String
Do While nClave <> "n"
nClave = InputBox("Ingrese Clave")
If bClaves(nClave, AClaves()) Then
MsgBox ("Clave duplicado")
Else
AClaves(cont) = nClave
cont = cont + 1
End If
Loop
End Sub
Function to search for repeated data within the array.
Function bClaves(ByVal clve As String, ByRef Datos() As String) As Boolean
bClaves = False
Dim clave As Variant
For Each clave In Datos
If clave <> "" Then
If clave = clve Then
bClaves = True
End If
End If
Next
End Function
I have found the solution to my problem, I attach code in case it helps someone.