Create Array via function - how do I make this work?

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
Hey,

here is my code:

Code:
Sub CompileData()
Dim DataSheet As Worksheet, CalcSheet As Worksheet
Dim Columns(), CalcState, HPGs()

Columns() = Array(1, 2, 3, 5, 6, 9, 12)
'Create HPG Array
HPGs() = CreateArray(DataSheet, Columns(0).Value)
End Sub
 
Function CreateArray(DataSheet As Worksheet, Clm As Long) As Variant
'Code
End Function

I get error 424 - Object required.

Thanks for the help.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Ok changed it and now it still doesnt work, new code:

Code:
Sub CompileData()
Dim DataSheet As Worksheet, CalcSheet As Worksheet
Dim Clms(), CalcState, HPGs()
Dim i As Long, LastColumn As Long, LastRow As Long
 
Clms() = Array(1, 2, 3, 5, 6, 9, 12)
 
HPGs() = CreateArray(DataSheet, Clms(0).Value)
End Sub
 
Upvote 0
Whats the code in your CreateArray function?
Which line does the error comes?
Is it still the same error?
 
Upvote 0
Ok changed it yet again and now it still doesnt work, new code:

Code:
Sub CompileData()
Dim DataSheet As Worksheet, CalcSheet As Worksheet
Dim Clms(), CalcState, HPGs()
Dim i As Long, LastColumn As Long, LastRow As Long
 
Clms() = Array(1, 2, 3, 5, 6, 9, 12)
i = Clms(0)
 
HPGs() = CreateArray(DataSheet, i)
End Sub

Code:
Function CreateArray(DataSheet As Worksheet, Clm As Long)
 
'Code
 
End Function
 
Upvote 0
Ok changed it and now it still doesnt work, new code:

Code:
Sub CompileData()
Dim DataSheet As Worksheet, CalcSheet As Worksheet
Dim Clms(), CalcState, HPGs()
Dim i As Long, LastColumn As Long, LastRow As Long
 
Clms() = Array(1, 2, 3, 5, 6, 9, 12)
 
HPGs() = CreateArray(DataSheet, Clms(0).Value)
End Sub

Hi

Clms() is an array, not an object, it does not have the property .Value or any other property.
 
Upvote 0
Ok, I actually got a problem within the function.

Here is the code to the function:

Code:
Function CreateArray(DataSheet As Worksheet, Clm As Long) As Variant
Dim Rng As Range, Dn As Range
DataSheet.Activate
Set Rng = DataSheet.Range(Cells(2, Clm), Cells(DataSheet.Columns(Clm).Rows.Count.End(xlUp), Clm))
With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
For Each Dn In Rng
    If Not .Exists(Dn.Value) Then
        .Add Dn.Value, [COLOR=red]CreateArray(Dn)
[/COLOR]    End If
Next
End With

Now problem with the red part. Argument not optional, how do I make it work?
 
Last edited:
Upvote 0
I want it to be an array though. How do I work around that. Basically, the function should start and values should be added to the function which then goes back to the main sub as an array. What am I doing wrong?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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