ByRef argument type mismatch

30percent

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

I have the following code. However this line of code throw an error message.

col_Arr = return_column(rng_column_loop, previous_Month)

Error message: Compile ErrorByRef argument type mismatch

The function requires range as argument. I passed in range. So why was the mismatch?
thank you

Code:
sub test()
Dim col_Arr() As Variant
finalCol = ThisWorkbook.Worksheets("Daily Totals").Cells(2, Sheets("Daily Totals").Columns.Count).End(xlToLeft).Column


Set rng_column_loop = ThisWorkbook.Worksheets("Daily Totals")("G2:G" & finalCol)
previous_Month = current_Month - 1


col_Arr = return_column(rng_column_loop, previous_Month)


end sub


Function return_column(rng_column_loop As Range, previous_Month As Long) As Variant


Dim cel As Range
Dim lastCol As Long
Dim firstCol As Long
For Each cel In rng.Cells
    With cel
        If cel.Value = previous_Month Then
            firstCol = cel.Column
            lastCol = cel.Column
        End If
        
    End With
Next cel


return_column = Array(firstCol, lastCol)


End Function
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You haven't declared the variables rng_column_loop and previous_Month, they need to be declared as Range and Long respectively.
Code:
Dim rng_column_loop As Range
Dim previous_Month As Long
 
Upvote 0

Forum statistics

Threads
1,216,215
Messages
6,129,557
Members
449,516
Latest member
lukaderanged

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