Problem when using an array returend by a function

Grand

Board Regular
Joined
May 11, 2017
Messages
52
Hi
I am getting error (Can't assign to array); also "empty array" error when trying to use an array that contains two values and is returned by a function in the following code :


Code:
Function ImportSourceFile()

Dim NymberOfUpdates As String
Dim NumberOfSheets As String
Dim CheckUpdateStatus(1) As Integer

Set SourceWorkBook = ActiveWorkbook

 CheckUpdateStatus = CheckIfAnyNewUpdate(SourceWorkBook, NewOld, DMSCCNR)' this gives me the error or Can't sign to array
 NumberOfSheets = CheckUpdateStatus(0) ' number of sheets containing data
 NymberOfUpdates = CheckUpdateStatus(1) ' number of newly updated stuff

End Function

Function CheckIfAnyNewUpdate(MyWB As Workbook, MyStatus As String, MYdocNrs() As String) As Integer
Dim TempString As String
Dim MyWSheets As Worksheet
Dim MySheets() As String
Dim TRowsSourceFile As Long
Dim SheetCounter As Integer
Dim ReturnValues(1) As Integer
Dim NumberOfDocs As Long

     SheetCounter = 0
     NumberOfDocs = 0
     
     For Each MyWSheets In MyQBIQWB.Worksheets
       If InStr(1, Left(MyWSheets.Name, 5), "Sheet", vbTextCompare) > 0 Then ' will check for names starting with "Sheet"..
           SheetCounter = SheetCounter + 1


          
           TRowsSourceFile = MyWB.Sheets(MyWSheets.Name).UsedRange.Rows.Count
           
           If MyWB.Worksheets(MyWSheets.Name).AutoFilterMode = False Then
            MyWB.Worksheets(MyWSheets.Name).Rows("1:1").AutoFilter
           End If
           
           MyWB.Worksheets(MyWSheets.Name).Range("A2:J" & TRowsSourceFile).AutoFilter Field:=4, _
           Criteria1:=MyStatus, Operator:=xlFilterValues   
       
           MyWB.Worksheets(MyWSheets.Name).Range("A2:J" & TRowsSourceFile).AutoFilter Field:=1, _
           Criteria1:=MYdocNrs, Operator:=xlFilterValues   
         

           
           NumberOfDocs = NumberOfDocs + MyWB.Worksheets(MyWSheets.Name).Range("A1:A" & TRowsSourceFile).Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
       End If
     Next MyWSheets



ReturnValues(0) = CInt(SheetCounter)
ReturnValues(1) = CInt(NumberOfDocs)

 CheckIfAnyUpdate = ReturnValues()
End Function

Thanks so much for any help :)
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Declare CheckUpdateStatus as Variant and don't set its dimensions.
Code:
Dim CheckUpdateStatus As Variant
 
Upvote 0
Did that and get the same error "Can't assign to array".at the same line as before:

Dim CheckUpdateStatus() As Variant
CheckUpdateStatus = CheckIfAnyNewUpdate(SourceWorkBook, NewOld, DMSCCNR)' gives error
 
Last edited:
Upvote 0
Rich (BB code):
Dim CheckUpdateStatus As Variant
Isn't the same as:
Rich (BB code):
Dim CheckUpdateStatus() As Variant
 
Upvote 0
Totally on spot. Sorry for not being attentive enough. Beside that, I found out actually that I was not returning anything as the function name is "CheckIfAnyNewUpdate" and not "CheckIfAnyUpdate". I am no sure why I did change the name as updates are usually new. Anyways, it works now and I am thankfull.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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