How do I determine an Array's index?

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
I'm toying around with using arrays instead of working in ranges.
Here is a simple array

Code:
Sub dotest()
Dim DirArray As Variant
starttime = Timer
DirArray = Range("c:t").Value
For Each x In DirArray
'Debug.Print x
Next
MsgBox Round(Timer - starttime, 2)
End Sub

While I want to load the entire c:t, what if I wanted a conditional statement in the FOR loop such as:

Code:
if x.column() = 3  then....
<== that syntax is wrong I know.
 
If you're only interested in a particular column, you could just do
Code:
Dim ary As Variant
Dim R As Long

ary = Range("I1:I100")
For R = 1 To UBound(ary, 1)
   If ary(R, 1) = "Haldens" Then ary(R, 1) = "Done"
Next R
Range("I1:I100").Value = ary
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If you're only interested in a particular column, you could just do
Code:
Dim ary As Variant
Dim R As Long

ary = Range("I1:I100")
For R = 1 To UBound(ary, 1)
   If ary(R, 1) = "Haldens" Then ary(R, 1) = "Done"
Next R
Range("I1:I100").Value = ary

Yes, I could but more than likely I'll be working with an entire range but have conditions for a specific column. Thanks for the added clarification.
 
Upvote 0

Forum statistics

Threads
1,223,706
Messages
6,173,998
Members
452,542
Latest member
Bricklin

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