+ Reply to Thread
Results 1 to 6 of 6

How to compare values with .Find function

  1. #1
    Registered User
    Join Date
    02-06-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    How to compare values with .Find function

    I'm trying to update one sheet with data from another sheet.
    The update is working, but I want to have a check for values that don't exist.

    Sheets(f_btc).Select
    With Worksheets(f_btc)
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With

    With Worksheets(f_btc).Range("A1:A" & LastRow)
    For i = 1 To LastRow
    Set c = .Find("HBN*", LookIn:=xlValues)
    If Not c Is Nothing Then

    ' gather some data from the first sheet

    WHBN = Range(c.Address).Value
    HBNfakt = Range(c.Address).Offset(0, 1).Value
    HBNmail = Range(c.Address).Offset(0, 2).Value
    Range(c.Address).Value = ""
    Range(c.Address).Offset(0, 1).Value = ""
    Range(c.Address).Offset(0, 2).Value = ""

    'Jump to the other sheet and find c.Address(WHBN)
    Sheets(f_vol).Select
    With Worksheets(f_vol)
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    End With
    With Worksheets(f_vol).Range("B1:B" & LastRow)

    'Here I want to check if the value WHDN exist on this sheet, if not show a message
    Set D = .Find(WHBN, LookIn:=xlValues)
    If Not D Is Nothing Then
    Range(D.Address).Offset(0, 2).Value = HBNfakt
    Range(D.Address).Offset(0, 16).Value = HBNmail
    Else
    MsgBox ("Can not find: " & D)
    End If
    End With
    Sheets(f_btc).Select
    Set c = .FindNext(c)
    End If
    Next i
    End With

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How to compare values with .Find function

    Please use code tags with your code.


    You may need to include an else statement to trap where is no match.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-06-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to compare values with .Find function

    How do you mean?
    I already have that in the code above.
    The problem is that the MsgBox displays for every hit, not only for the posts that don't match...

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How to compare values with .Find function

    If there is a match

    Please Login or Register  to view this content.
    HBNfakt and HBNmail. Where do you get these values from? They are not part of either D, or WHBN,

  5. #5
    Registered User
    Join Date
    02-06-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to compare values with .Find function

    From Worksheets(f_btc)
    WHBN = Range(c.Address).Value
    HBNfakt = Range(c.Address).Offset(0, 1).Value
    HBNmail = Range(c.Address).Offset(0, 2).Value

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How to compare values with .Find function

    Olafson,
    It is difficult to read your code as you have not wrapped it with tags.
    You have two sets of
    Please Login or Register  to view this content.
    but only one else statement

+ 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