I am trying to loop through multiple worksheets and find values above a certain threshold. If those values are found, the whole line containing the value above threshold should be copied into a new created "Summary"-Sheet.
My UserForm so far looks like this:

And my code like this:
Option Explicit
Private Sub UserForm_Initialize()
Dim N As Long
For N = 1 To ActiveWorkbook.Sheets.Count
Sheets_txt.AddItem ActiveWorkbook.Sheets(N).Name
Next N
End Sub
Private Sub CommandButton1_Click()
Dim SelectedItems As String
Dim column As String
Dim WS As Worksheet
Dim i As Long, j As Long, lastRow As Long, k As Long
Dim sh As Worksheet
Dim sheetsList As Variant
Dim threshold As Long
Set WS = ThisWorkbook.Worksheets.Add
WS.Name = "Summary"
threshold = Me.Threshold_txt.Value
column = Me.Column_txt.Value
j = 2
For k = 0 To Sheets_txt.ListCount - 1
If Sheets_txt.Selected(i) = True Then
SelectedItems = SelectedItems & Sheets_txt.List(i)
lastRow = SelectedItems.Cells(SelectedItems.Rows.Count, "A").End(xlUp).Row
For i = 4 To lastRow
If SelectedItems.Range(column & i) > threshold Or SelectedItems.Range(column & i) < -threshold Then
SelectedItems.Range("a" & i & ":n" & i).Copy Destination:=WS.Range("A" & j)
WS.Range("N" & j) = SelectedItems.Name
j = j + 1
End If
Next i
End If
Next k
WS.Columns("A:N").AutoFit
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
However I am struggeling with the For loop. The code should be looping through all selected sheets and do the things I wrote above. However using a variable SelectedItems to store all strings that meet the condition of If Sheets_txt.Selected(i) = True is not working. In my case it debugs at lastRow = SelectedItems.Cells(SelectedItems.Rows.Count, "A").End(xlUp).Row and points to (SelectedItems.Rows.Count.
How can I get this loop working? Any help appreciated!
SelectedItemsdoesn't work quite as you might expect. I'll try to post back when I'm at my computer. I don't remember the exact syntax, but I believe you loop throughItemsand test whether they are selected.