Consulting

Results 1 to 5 of 5

Thread: Return Value into userform.

  1. #1
    VBAX Contributor
    Joined
    Aug 2011
    Posts
    126
    Location

    Return Value into userform.

    Missing something simple here, I know...

    Trying to return the value of a cell which is 2 columns right of the cell in Worksheet "Data 2" that contains the same value that is in TextboxQuoteNumber.

    [vba]TextBoxSalesman.Value = Sheets("Data 2").Find(TextboxQuoteNumber.Value).Offset(0, 2).Value[/vba]

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Try
    [VBA]TextBoxSalesman.Value = CStr(Sheets("Data 2").Cells.Find(TextboxQuoteNumber.Value).Offset(0, 2).Value)[/VBA]You may have to convert the TextBoxQuoteNumber.Value if the cells contain other than text.

  3. #3
    VBAX Contributor
    Joined
    Aug 2011
    Posts
    126
    Location
    Thank you Mike.
    I'm still getting an error message. "Object variable or With block variable not set". I set it up With (and without)... but.. continuing to beat myself up.

    [VBA] With Sheets("Data 2")
    TextboxQuoteNumber.Value = QuoteNo.TextBox_QuoteNo.Value
    TextBoxSalesman.Value = CStr(Sheets("Data 2").cells.Find(TextboxQuoteNumber.Value).Offset(0, 2).Value)
    End With[/VBA] Thanks for any additional recommendations !

  4. #4
    The error means the search string wasn't found. I advise you to also use the other agruments of the Find method to prevent it using the wrong settings.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    That means that the activeworkbook has no sheet named "Data 2".

    You will also get an error if there is no cell found.
    [VBA] Dim f As Range
    With Sheets("Data 2")
    TextboxQuoteNumber.Value = QuoteNo.TextBox_QuoteNo.Value
    Set f = Sheets("Data 2").Cells.Find(TextboxQuoteNumber.Value)
    If f Is Nothing Then Exit Sub
    TextBoxSalesman.Value = CStr(f.Offset(0, 2).Value)
    End With[/VBA]

Posting Permissions

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