Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:19:30+00:00 2026-05-28T06:19:30+00:00

The following function returns a type mismatch. I don’t understand, as I paid attention

  • 0

The following function returns a “type mismatch”. I don’t understand, as I paid attention to using the “Set” instruction to return my resulting range.

I debugged the function, I get a proper range to return, so the problem is elsewhere.. Hmmmm…

Function getVals(column As String) As Range
    Dim col As Variant
    col = Application.Match(column, ThisWorkbook.ActiveSheet.Range("1:1"), 0)
    Dim rng As Range
    Set rng = ThisWorkbook.ActiveSheet.Cells(1, col)
    Set rng = rng.Offset(1, 0)
    Set rng = Range(rng, rng.End(xlDown))
    Set getVals = rng
End Function

Thanks in advance guys for any help 🙂

UPDATE : I am looking at how to send my results as an array. I tried combinations of the function returning “variant”/”variant()” type, and passing rng.value2 as result, but no success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:19:31+00:00Added an answer on May 28, 2026 at 6:19 am

    To return your results as an array of values, simply change the return type to Variant and return rng.Value. The below code works for me as long as the passed column string exists in ThisWorkbook.ActiveSheet.Range("1:1").

    Function getVals(column As String) As Variant
        Dim col As Variant
        col = Application.Match(column, ThisWorkbook.ActiveSheet.Range("1:1"), 0)
        Dim rng As Range
        Set rng = ThisWorkbook.ActiveSheet.Cells(1, col)
        Set rng = rng.Offset(1, 0)
        Set rng = Range(rng, rng.End(xlDown))
        getVals = rng.Value
    End Function
    
    Sub TestingGetVals()
       Dim v As Variant, i As Integer
       v = getVals("a")  ' returns a 2-D array
       For i = 1 To UBound(v)
          Debug.Print v(i, 1)
       Next i
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following function: DataTable go() { return someTableAdapter.getSomeData(); } When I set a
I have a function that returns the following type: IEnumerable<IGrouping<String, ExportTransaction>> In this function
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I'm having a weird problem with the following function, which returns a string with
How come the following doesn't work? CREATE FUNCTION Test (@top integer) RETURNS TABLE AS
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
Suppose I've the following function: function mul() { return array_reduce(func_get_args(), '*'); } Is is
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
assume this following function: int binaryTree::findHeight(node *n) { if (n == NULL) { return
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.