Private Sub CommandButton1_Click()
Dim serialNumbers As String
Dim serialArray() As String
Dim i As Integer
Dim Total_Rows As Long
Dim Active_Column As Integer
Dim Top_Cell As Range
' Get the serial numbers from the TextBox
serialNumbers = TextBox1.Value
' Split the serial numbers into an array
serialArray = Split(serialNumbers, ",")
' Set the range for inserting serial numbers
Total_Rows = ActiveSheet.UsedRange.Rows.Count + 1
Active_Column = 1
Set Top_Cell = ActiveSheet.Range("B2")
' Find the last row with data in column A
Dim lastRow As Long
lastRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
' Loop through the array and insert serial numbers into the sheet
For i = LBound(serialArray) To UBound(serialArray)
If Top_Cell.Cells(lastRow + i, 1).Value = "" Then
For Each Ctrl In UserForm1.Controls
If TypeName(Ctrl) = "TextBox" Then
Top_Cell.Cells(lastRow + i, Active_Column).Value = Trim(serialArray(i))
Active_Column = Active_Column + 1
End If
Next Ctrl
Exit For
End If
Next i
' Clear the TextBox after insertion
TextBox1.Value = ""
End Sub
Private Sub ListBox1_Click()
For i = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.Selected(i) = True Then
Worksheets(UserForm1.ListBox1.List(i)).Activate
End If
Next i
End Sub