PDA

View Full Version : Array loop values



NicheD
09-26-2022, 03:20 AM
Hello, I have two columns (C and D) filled with values. If column D is more than zero but less than 10 i want the cell (and cell C from the same row) to be picked. I cannot get this to work. Any suggestions?







Dim lrowD As Long, frowD As Long, i As Long
Dim arr As Variant
Dim rng As Range
Dim Col1 as String

With ActiveSheet


frowD = .Cells(.Rows.Count, "D").End(xlUp).Row - 14
lrowD = .Cells(.Rows.Count, "D").End(xlUp).Row - 3
Set rng = ActiveSheet.Range(.Cells(frowD, "B"), .Cells(lrowD, "D"))
arr = rng


For i = 1 To UBound(arr)
If arr(i, 3) > 0 and arr(i, 3) < 10 Then
Col1 = Col1 & arr(i, 2) & vbNewLine & arr(i, 3)

End If
Next i
end with

snb
09-26-2022, 03:39 AM
Sub M_snb()
sn = cells(1,4).currentregion

for j = ubound(sn)-14 to ubound(sn) -3
if sn(j,4)>0 and sn(j,4)<10 then exit for
next

cells(j,3).select
End Sub

SamT
09-26-2022, 09:59 AM
Set rng = ActiveSheet.Range(.Cells(frowD, "B"), .Cells(lrowD, "D"))
arr = rng



'
'
'
Arr = .Range(.Cells(frowD, "B"), .Cells(lrowD, "D")).Value

For i = 1 To UBound(arr)
If arr(i, 3) > 0 and arr(i, 3) < 10 Then
Col1 = Col1 & arr(i, 2) & " : " & arr(i, 3) & vbCrLf
'
'
'
Msgbox Col1

It would be worth your while to comprehend what Sub M_snb is doing.