ByRef argument type mismatch

30percent

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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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