I am trying to display data in a text box based on a search I am doing with a macro. I am searching for an order number: 80038209. There is one Column (B) that contains all order numbers. The same order number can be in Cell B2 to B11. There are corresponding data for that specific oder number in Column C, D, E etc. Which I need to also pull for all 11 order number matches in Column B to display along in a text box.
Example:
| Sales Order | Item | Note |
|---|---|---|
| 80038209 | Thing | Keep it |
| 80038209 | Other thing | Eat this |
| 80038209 | Old Hat | Throw |
| 80038209 | Cat | Hide |
| 80077777 | Shovel | Hide |
| 80077777 | More thing | Steal |
| 80077777 | Shoe | Call President |
When I enter my order number for the search, I get the first result of the first match only, I do not get all the matches.
This is what I get:
This is what I'm trying to achieve:
This is my current code:
Public Sub UserForm_Initialize()
limiter_a = "^#11^"
limiter_b = "^#12^"
End Sub
Private Sub suchbutton_Click()
Dim fullstring As String, searchstring As String
Dim sofound As String, customerfound As String, pickqtyfound As String
Dim itemnote As String, itemspecial As String, batch As String
Dim sonumber As String, wave As String
Dim placeholder1 As String, placeholder2 As String, placeholder3 As String
Dim ergebnis As String
Dim j As Long
Dim lenght_a As Long, lenght_b As Long
Set ws = ThisWorkbook.Worksheets("INPUT1")
placeholder1 = "D"
placeholder2 = "A"
placeholder3 = "J"
sonumber = "B"
wave = "G"
batch = "L"
pickqtyfound = "N"
itemnote = "R"
itemspecial = "T"
lenght_a = Len(limiter_a)
lenght_b = Len(limiter_b)
fullstring = SucheTeilenummer.userinput.Value
openPos = InStr(fullstring, limiter_a)
closePos = InStr(fullstring, limiter_b)
If openPos > "0" And closePos > "0" Then
searchstring = Mid(fullstring, openPos + lenght_a, closePos - openPos - lenght_b)
lastRow = ws.Cells(ws.Rows.Count, sonumber).End(xlUp).Row
For j = lastRow To 2 Step -1
If ws.Range(sonumber & j).Value = searchstring Then
booFound = True
SucheTeilenummer.sofound = ws.Range(sonumber & j).Value
SucheTeilenummer.customerfound = ws.Range(wave & j).Value
SucheTeilenummer.pickqtyfound = ws.Range(pickqtyfound & j).Value
SucheTeilenummer.itemnote = ws.Range(itemnote & j).Value
SucheTeilenummer.itemspecial = ws.Range(itemspecial & j).Value
SucheTeilenummer.batch = ws.Range(batch & j).Value
SucheTeilenummer.placeholder1 = ws.Range(placeholder1 & j).Value
SucheTeilenummer.placeholder2 = ws.Range(placeholder2 & j).Value
SucheTeilenummer.placeholder3 = ws.Range(placeholder3 & j).Value
End If
Next j
Else
searchstring = "Keine Limiter gefunden"
End If
If Not booFound Then
SucheTeilenummer.sofound = searchstring
emptySucheForm
End If
SucheTeilenummer.userinput.Value = ""
fullstring = ""
ergebnis = ""
SucheTeilenummer.userinput.SetFocus
End Sub
Private Sub emptySucheForm()
SucheTeilenummer.customerfound = ""
SucheTeilenummer.pickqtyfound = ""
SucheTeilenummer.itemnote = ""
SucheTeilenummer.itemspecial = ""
SucheTeilenummer.batch = ""
SucheTeilenummer.placeholder1 = ""
SucheTeilenummer.placeholder2 = ""
SucheTeilenummer.placeholder3 = ""
End Sub
Help would be very much appreciated.
Thanks.

