Excel VBA Werte Suchen, die durch while-Schleife, gespeichert im array, und pass auf unterschiedlichen sub

First off, ich Schätze jede Hilfe, die jedermann anbieten kann. Ich Schreibe ein makro, dass dem Benutzer ein Formular zur Eingabe einer Zifferntaste. Die form wird gesucht in einer Tabelle die-Taste und fügen die entsprechenden Namen an den Schlüssel angehängt. Die Daten können mehrere Namen pro Taste und es wird variieren je nach Taste. Ich möchte eine Schleife durch die Daten .Finden und .FindNext, und finden Sie alle möglichen Namen an den Schlüssel angehängt (ich erreicht habe, das Teil). Der Teil, den ich bin Probleme mit, ist während der Schleife speichern die Namen in ein array, das ich übergeben kann, der zu einem anderen sub. Ich möchte das array übergeben, so dass der Benutzer auf einen anderen command-button und Durchlaufen Sie die möglichen Namen, die vor der Auswahl einer.

Private Sub FindNameButton_Click()
Dim KeyMatch As Long
Dim NameRow As Long
FindName As Range
KeyMatch = KeyBox.Value ' The UserForm input box

With Worksheets("Master List"). Range("D:D")
Set FindName = .Find(What:= KeyMatch, LookAt:= xlWhole, LookIn:= xlValues,           MatchCase:= False)
If not FindName Is Nothing Then 
FirstAddress = FindName.Address
Do
Application.GoTo FindName
NameRow = ActiveCell.Row
Cells(NameRow, 2).Select 'Selects the name associated with the key identifier
NameBox.Value = ActiveCell.Value 'Fills the UserForm box with the name
' I would like to fill the array here with each name is it passes through but I have   no idea how

NameArray(i) = ActiveCell.Value ' ??????

Set FindName = .FindNext(FindName)
Loop While FindName is Nothing and FristAddress <> FindName.Address
End With
End Sub

Private Sub NextNameButton_Click()
Static cnt As Long
If cnt <= Ubound(NameArray) Then
NameBox.Value = NameArray(cnt) 'Fill UserForm Name Box with name from Name Array

Else
cnt = 0
End If

cnt = cnt + 1 ' increase every time button is clicked
End Sub
InformationsquelleAutor Chris D | 2013-06-03
Schreibe einen Kommentar