Loop through array to collect values.

NichoD

Board Regular
Joined
Jul 31, 2022
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Array loop values
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top