Source of subscript error (9)?

michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
In the below code, I'm getting a subscript error on the line in red. Any ideas why this would be?

Code:
Private Sub OK_Click()


Dim x As Long, ERow As Long
Dim PINamesArray As Variant
Dim size As Long
Dim SearchRange As Range
Dim FindRow As Long
Dim k1 As Worksheet
Dim k2 As Worksheet


Set k1 = Worksheets("NA")
Set k2 = Worksheets("Dropped-NotSelected")
Set SearchRange = k1.Range("D5:D2000")


ERow = k2.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues, After:=k2.Range("A4")).Row + 1


PINamesArray = Split(Me.PINames, "; ")


size = UBound(PINamesArray) - LBound(PINamesArray) + 1


For x = 1 To size


[COLOR=#ff0000]    FindRow = SearchRange.Find(What:=PINamesArray(x)).Row[/COLOR]


    If FindRow <> 0 Then
        Rows(FindRow).Copy
        k2.Cells(ERow, 1).PasteAll
        Rows(FindRow).Delete Shift:=xlShiftUp
    End If


Next x


Unload Me


End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Why do you have this?
Code:
size = UBound(PINamesArray) - LBound(PINamesArray) + 1
If you want to loop through all the items in PINamesArray use this.
Code:
For x = LBound(PINamesArray) To UBound(PINamesArray)

If you use this method then you don't need to calculate the size of the array and it doesn't matter if it's 0-indexed or 1-indexed.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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