Results 1 to 4 of 4

Thread: Find returning value not range
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Sep 2015
    Posts
    37
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Find returning value not range

    Hello,

    I'm attempting to use a find function in my code. Yet, when I run it, it puts the value of the cell into the variable and not the range.

    Could someone please tell me what i am doing wrong?

    Sub Saving_Crack()


    Dim IDnum As String
    Dim filePath As String
    Dim crackIDnum As Range
    Dim wt As Variant
    Dim crackIDwkbk As String
    Dim a As Range


    'to get the ID number


    crackIDwkbk = ActiveWorkbook.Name
    Sheets("Properties").Activate
    IDnum = Range("B2").Value




    'go to masterlist
    Windows("Check Defect Data Inputs").Activate
    Set crackIDnum = Range("B1:B123").Find(IDnum)
    Debug.Print crackIDnum




    'flaw label as a variable
    Range(crackIDnum).Offset(0, 15).Value = wt

    End Sub


  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,958
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Find returning value not range

    It is putting the range object into the variable not the cell value, if you use
    Code:
    Debug.Print crackIDnum.Address
    you can see that.
    Also this line
    Code:
    Range(crackIDnum).Offset(0, 15).Value = wt
    should be
    Code:
    crackIDnum.Offset(0, 15).Value = wt
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    New Member
    Join Date
    Sep 2015
    Posts
    37
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Find returning value not range

    So say the find function finds ("B3") as the range that contains the value. By removing the Debug Print statement the variable will be the range of B3?

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    27,958
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Find returning value not range

    The variable will be Range("B3") with or without the Debug.Print line.

    Debug.Print does not change the variable it simply prints information to the Immediate window.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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