ByRef argument type mismatch

30percent

Board Regular
Joined
May 5, 2011
Messages
101
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
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,168
Messages
5,594,632
Members
413,919
Latest member
ZaxAlchemist

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
Top