Run-time error 9 problem

bebe1279

Board Regular
Joined
May 24, 2014
Messages
60
Hi everyone

I've been working on a project and have come across a run time error and I'm not sure what's wrong.
Here's the code I have

Code:
Sub GenerateSummaryYee()

Dim lr As Long
Dim adr As String
Dim jobt As Long
Dim bal As Long

'Define Yee array
 Yee = Array("1235 Law 11-8a", "2526 Roof", "2922 Roof", "1110 Roof", "2145-2147 Roof", "20 East", "1235 Roof", "2125", "2526 Local Law 11", _
 "2070 Roof", "1221-1227", "3556 Roof", "2805 G.C Roof", "2499 Roof", "1235 Windows", "1900 Roof", "960 Windows", "2185 G.C Roof", "2720 Roof", _
 "1895 Roof", "20 East Roof", "2141-2143 Roof", "2685", "2499 Roof", "2499 Brick work", "940 Windows", "2185 Bolton Roof", "3525 Roof", _
 "1000 G.C - Brick work, Lintels & Sills")

'Loop through worksheets of Yee array
For i = LBound(Yee) To UBound(Yee)
   
 With Worksheets(Yee(i))
   
 'find last row of data
    lr = .Cells(Rows.Count, 1).End(xlUp).Row
    
    'add values to variables
    adr = .Cells(lr, 1).Value
    jobt = .Cells(lr, 2).Value
    bal = .Cells(lr, 5).Value
    End With
        
        'dump data into summary sheet
        With Worksheets("SUMMARY")
        'start at row 7
         If x = "" Then x = 7
         'If the value of bal is 0 then do nothing and go to next
         If bal <> 0 Then
            'Otherwise, assign values to cells
            .Cells(x, 1).Value = adr
            .Cells(x, 2).Value = jobt
            .Cells(x, 3).Value = bal
        x = x + 1
        End If
        End With
Next i
End Sub

The run-time error occurs on the following line

Code:
With Worksheets(Yee(i))

Any idea/help is much appreciated
Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
At least one of the sheet names in the array doesn't exactly match the actual sheet name. Click debug and hover the cursor over the variable i to see its value and determine which name in the array doesn't match.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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