error 2007

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code. When I run it - this line of code triggers an error:

Set rng_clients_prev = ThisWorkbook.Worksheets("Daily Totals").Range(Cells(4, col_Arr(0)), Cells(finalRow_clients, col_Arr(1)))

error message:
Run-time error '1004':
Application-defined or object-defined error

From watches window: Value of Cells(4, col_Arr(0)) is error 2007.
Not sure what what means.

I replaced col_Arr(0) and col_Arr(1) and finalRow_clients with their actual values. I still get the same error message.

Set rng_clients_prev = ThisWorkbook.Worksheets("Daily Totals").Range(Cells(4, 14), Cells(44, 36)

Wonder if someone could point out what caused the error?
Thank you

Code:
Function return_column(rng_column_loop As Range, previous_Month As Integer) As Variant


Dim cel As Range
Dim lastCol As Long
Dim firstCol As Long
Dim counter As Integer


counter = 0


For Each cel In rng_column_loop.Cells
    With cel
        If .Value = previous_Month Then
            If counter = 0 Then
                firstCol = .Column
                counter = counter + 1
            End If
            lastCol = .Column
        End If
        
    End With
Next cel


return_column = Array(firstCol, lastCol)


End Function


Sub update_Month()


Dim col_Arr() As Variant


previous_Month = current_Month - 1


col_Arr = return_column(rng_column_loop, previous_Month)


Set rng_clients_prev = ThisWorkbook.Worksheets("Daily Totals").Range(Cells(4, col_Arr(0)), Cells(finalRow_clients, col_Arr(1)))


prev_MTD_clients = WorksheetFunction.Sum(rng_clients_prev)






End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Typo in the worksheet name maybe?

I just named a sheet as "Daily Totals" in a file that I had open and tried
Code:
Set rng_clients_prev = ThisWorkbook.Worksheets("Daily Totals").Range(Cells(4, 14), Cells(44, 36))
which worked without error.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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