I have a small problem that I hope can guide me, it turns out that I have to store an array and for each data I'm going to store, verify if it has not been previously entered, the difficulty I have is that I define an array of 10 elements. , but the user may need to enter 15, 20, 30 on items. I have tried to use the ReDim instruction but I have not managed to do it since I get the error of The matrix already has dimensions
Annex 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