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
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