Hello all and thanks for the view. Hopefully it is a fairly easy thing I'm missing.
I'm running a loop where for each cell in a column on a sheet, if conditions are met, cell.value and cell.offset(0, 1).value would be added to a list with two columns (row i, column1) and (row i , column 2) where i is the next available row in the list.
The scripting works when i is replaced with a row number but only adds to a single "row" in the List. My thought was to do something like - Range("A" & Rows.Count).End(xlUp).Offset(1, 0) - but the list range for columns and rows doesn't seem to act the same as the range in the worksheet. But I'm surly missing something.
'thought about using this as a reference range for the listbox (since this is equal to cell.value and cell.Offset(0, 1).Value) but it decouples the For Each loop respective to the range in the loop
Dim samtar As Range
Set samtar = Sheets(1).Range("D23:E3094")
Any thoughts or assistance is greatly appreciated!
I'm running a loop where for each cell in a column on a sheet, if conditions are met, cell.value and cell.offset(0, 1).value would be added to a list with two columns (row i, column1) and (row i , column 2) where i is the next available row in the list.
The scripting works when i is replaced with a row number but only adds to a single "row" in the List. My thought was to do something like - Range("A" & Rows.Count).End(xlUp).Offset(1, 0) - but the list range for columns and rows doesn't seem to act the same as the range in the worksheet. But I'm surly missing something.
'thought about using this as a reference range for the listbox (since this is equal to cell.value and cell.Offset(0, 1).Value) but it decouples the For Each loop respective to the range in the loop
Dim samtar As Range
Set samtar = Sheets(1).Range("D23:E3094")
Any thoughts or assistance is greatly appreciated!
VBA Code:
Private Sub PopulateReviewList_Click()
Dim i As Long
Dim samname As Range
Set samname = Sheets(1).Range("D23:D3094")
For Each cell In samname
If cell.Offset(0, 3).Value = "Review" Or cell.Offset(0, 4).Value = "Review" Or cell.Offset(0, 5).Value = "Review" Then
With UserForm1.ReviewSampleList
.AddItem
'when i is replaced with 1, the list only populates the first row, regardless of how many entries qualify to be added, which makes sense
.List(i, 0) = cell.Value
.List(i, 1) = cell.Offset(0, 1).Value
End With
Else
End If
Next
End Sub