+ Reply to Thread
Results 1 to 6 of 6

compare cells

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    compare cells

    Hello guys, you helped me lots of times recently, but this is little bit tricky problem ... so :
    - I have external data, which are loaded every 1 second
    - each row has in column A unique number
    - sometimes this row is deleted (from external source)

    and I need "just" find If something is new (for this I use
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("A1:A30")) Is Nothing Then
    
    End If
    End Sub
    and If yes, just copy it somewhere
    btw. I will have to use some other criteria, but I think I will be able to modify it and I dont want to complicate it now I have lots of problem to explain myself

    I thought that I could store all unique numbers in variables, but there will be lots of variables maybe somebody has better solution?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: compare cells

    store your unique numbers in a column.

    It is then easy to use find to look for a new number, using an exact match.

    If there is no match then this is a new entry.

  3. #3
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: compare cells

    mehmetcik - your solution looks better, but I am not sure if it so simple could you be please more specific? thank you

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: compare cells

    Here is a sample of what I meant.

    study the data.

    there are only three unique numbers in my list.#

    Modify the list if you want

    then run the macro.

    
    Sub Macro1()
    On Error Resume Next
    
    'Copy column A into an array. Saves having lots of read commands
    Sheets("New Data (2)").Select
    myarray = Range("A1:A" & Range("A1").End(xlDown).Row).Value
    
    'Loop through the ref numbers in your array
    For Count = 1 To UBound(myarray)
    IndexVal = myarray(Count, 1)
    
    'Does your ref no exist in your list of numbers?
    Sheets("Unique References").Select
        Columns("A:A").Select
        Selection.Find(What:=IndexVal, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
    
    'If not then
    If ActiveCell.Value <> IndexVal Then
    
    'Add it to your list
    Cells(Range("A1").End(xlDown).Row + 1, 1).Value = IndexVal
    
    'Copy the entry to another sheet
    With Sheets("Extracted Data")
    NR = .Range("A1").End(xlDown).Row + 1
    Sheets("New Data (2)").Range("A" & Count & ":G" & Count).Copy Destination:=.Range("A" & NR)
    End With
    
    End If
    Next
    End Sub
    Attached Files Attached Files
    Last edited by mehmetcik; 11-02-2013 at 12:44 PM.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,968

    Re: compare cells

    If you could have your data added vertically instead of horizontal, you could use a countif() function to ID the 1st occurance of an entry, and then either just filter on those, or filter and copy/past to the new location.

    Take a look atthe attached to see what I mean
    Attached Files Attached Files
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: compare cells

    thx for answer FDibbins, but I cannot use your solution because datas are added only horizontally and I cant change it

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 09-06-2013, 02:25 PM
  2. Compare two cells, if equal move a third cells data to another cell
    By eriick in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-24-2013, 05:38 PM
  3. Replies: 6
    Last Post: 05-30-2012, 03:09 PM
  4. Compare 2 cells on sheet1 with 2 cells on sheet2 and copy unmatched rows to sheet3
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2010, 07:56 AM
  5. [SOLVED] How do I compare cells and if FALSE compare to next cell in EXCEL
    By Cindie in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-24-2006, 01:35 PM

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