+ Reply to Thread
Results 1 to 5 of 5

Object Required Error in VB Excel Program that Passes Range to a function

Hybrid View

  1. #1
    Registered User
    Join Date
    12-01-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    17

    Unhappy Object Required Error in VB Excel Program that Passes Range to a function

    Hi Friends,

    I am trying to pass the formula which gives a range of cells to a function called concatenate_Text which is defined as

    Public Function Concatenate_Text(Textrange As Range) As String
    Dim str_text As String
    Dim var_cell As Variant
        For Each var_cell In Textrange
            str_text = str_text & " " & var_cell
        Next
        Concatenate_Text = str_text
    End Function
    The macro that passes the range is this

    Dim TopCell As Range
    TopCell = "OFFSET('Data Tab'!$A$2,0,$B$16 - 1,INDEX($B$1:$B$15,$B$16,1),1))"
    Concatenate_Text (TopCell)
    When I try to execute this, it gives me an error saying "Object Required" error. The catch is "I want to send the results of the formula to the function Concatenate_Text ........
    Kindly explain where I am going wrong.

    Thanks in advance for your time
    Last edited by romperstomper; 12-06-2011 at 05:30 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,979

    Re: Object Required Error in VB Excel Program that Passes Range to a function

    Change the last line to:
    Concatenate_Text TopCell
    without the parentheses.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    12-01-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Object Required Error in VB Excel Program that Passes Range to a function

    Quote Originally Posted by romperstomper View Post
    Change the last line to:
    Concatenate_Text TopCell
    without the parentheses.
    Hi Roomperstomper,

    I tried, but did not work..
    I think its to do with the object definition. I am declaring the range variable.

    but some one please tell me, how to "Set" the range variable with the result of the formula....

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,979

    Re: Object Required Error in VB Excel Program that Passes Range to a function

    I didn't read the line above - you can't assign a range based on a formula like that. Best guess would be:
    Set TopCell = sheets("Data Tab").Range("A2").Offset(0, Range("B16").Value - 1).Resize(Range("B1:B15").cells(Range("B16").Value,1), 1)

  5. #5
    Registered User
    Join Date
    12-01-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Object Required Error in VB Excel Program that Passes Range to a function

    Wow, Thank you so much Romperstomper.. It is working super cool
    Last edited by romperstomper; 12-06-2011 at 05:29 AM. Reason: remove unnecessary quote

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1