sgp667
sgp667

Reputation: 1875

Compiler complaining about wrong Data Type

I have written folowing procedure, each time I try to run it compiled says that Data is a wrong data type. ChooseLineItem takes a range as a parameter, and as you can see if Data is not a range then ChooseLineItem will not be executed.

So my question is how do I get this code to compile?

Public Function MakeKeyValPairs(Data As Variant) As Variant()
    Dim LineItem As Integer
    Dim Headers As KeyValStruct

    If TypeName(Data) = "Range" Then
        LineItem = ChooseLineItem(Data)
    Else
        LineItem = 1
    End If
    Headers = FindHeaders(Data)

    MakeKeyValPairs = AssembleAray(Data, Headers, LineItem)
End Function

FYI The reason why Data is decared as a variant is because it has to be able to accept ranges and arrays.

Upvotes: 0

Views: 48

Answers (1)

AnalystCave.com
AnalystCave.com

Reputation: 4984

Try this:

Public Function MakeKeyValPairs(Data As Variant) As Variant()
        Dim LineItem As Integer, Headers As KeyValStruct, r as Range

        If TypeName(Data) = "Range" Then
        Set r = Data
        LineItem = ChooseLineItem(r)
    Else
        LineItem = 1
    End If
    Headers = FindHeaders(Data)

    MakeKeyValPairs = AssembleAray(Data, Headers, LineItem)
End Function

Upvotes: 3

Related Questions