VBA Help with Looping through an Array

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
HI, I am trying to loop through an array of words, It loops through but doesn't do anything, I know I am probably forgetting something, See code

Code:
Dim Rng As range, c As Long, Arr As Variant, I As Integer
'
        Arr = Array("IPN", "VPN", "PartNumber", "Part")
        For i = LBound(Arr, 1) To UBound(Arr, 1)
            Set Fnd = Cells.Find(Arr(c), range("A1"), xlValues, xlWhole, xlByRows, xlNext, False, False)
            If Not Fnd Is Nothing Then
            Set Rng = range(Fnd.Offset(1), Cells(Rows.Count, Fnd.Column).End(xlUp))
        End If
    Next i
        If Fnd Is Nothing Then Exit Sub
    Rng.Select
End Sub
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Your looping through with i, but your find arr is c, which will always be 0
Code:
For [COLOR=#ff0000]i[/COLOR] = LBound(Arr, 1) To UBound(Arr, 1)
            Set Fnd = Cells.Find(Arr([COLOR=#ff0000]c[/COLOR]), range("A1"), xlValues, xlWhole, xlByRows, xlNext, False, False)
Change one or the other
 
Upvote 0
Thanks you Fluff, I knew it would be something as simple as this, Also just realised that I need to move Rng.Select after Set Rng as it loops through and then exits the sub if no words are found even though it may of found 1, Thanks again
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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