Can be done like this
Option Explicit
Sub Check_Firmware()
Dim ArrPK() As String, SearchString As String 'Declare ArrPk as string array
Dim Firmware As Range, aCell As Range
Dim ws As Worksheet
Dim PkCounter As Long
Dim LstBox As msforms.ListBox
Set ws = ThisWorkbook.Sheets("Sheet1")
SearchString = "Controller Firmware Version"
Set LstBox = UserForm1.ListBox1
PkCounter = 1
With ws
'set range that will be source for searching
Set Firmware = .Range("F1:F" & .Cells(.Rows.Count, "F").End(xlUp).Row)
For Each aCell In Firmware 'loop each cell of desired range
If aCell.Value2 = SearchString Then 'if match found
ReDim Preserve ArrPK(1 To 2, 1 To PkCounter) 'redimension array.
ArrPK(1, PkCounter) = aCell.Offset(1, 0) 'firmware
ArrPK(2, PkCounter) = aCell.Offset(1, -2) 'serial no
PkCounter = PkCounter + 1 'increase counter for next match found
End If
Next
End With
With LstBox
.Clear
.ColumnCount = 2
.Width = 105
.ColumnWidths = "50;50"
For PkCounter = LBound(ArrPK(), 2) To UBound(ArrPK(), 2)
.AddItem 'add new item to listbox
'put values to newly added row
.List(PkCounter - 1, 0) = ArrPK(1, PkCounter) 'new row/column 0
'PkCounter - 1 because listbox is counted from 0
.List(PkCounter - 1, 1) = ArrPK(2, PkCounter)'new row/column 1
Next PkCounter
End With
UserForm1.Show
End Sub
EDIT:
ReDim Preserve ArrPK(1 To 2, 1 To PkCounter)
This sets new dimensions for array
So now you have 2 dimension array.
Preserve means that all values that are already in array will stay there
1 To 2 and 1 to PkCounter are new dimensions for array. When you find more matches then PkCounter grows and so do array.
Put a Breakpoint on With LstBox open "Locals" window. You'll see your ArrPK array there, and you'll be able to check what's inside of it.
You can read more about arrays on the web.
x.Value2 = "Search"the"Search"is not the variableSearchso you should remove the quotes" "here to use the variableSearch = "Controller Firmware Version"x.Value2 = "Search"You are looking for the string"Search", not for the string contained in the variableSearch. Usex.Value2 = Search. A better way could be to use .Find. You can usex.Offset(1,0).Value2andx.Offset(1,-2).Value2to access your data.