+ Reply to Thread
Results 1 to 2 of 2

Help with VB Script Compare and Update

Hybrid View

udprocks Help with VB Script Compare... 10-22-2017, 01:43 AM
jindon Re: Help with VB Script ... 10-22-2017, 03:08 AM
  1. #1
    Forum Contributor
    Join Date
    10-29-2014
    Location
    udaipur, rajasthan
    MS-Off Ver
    2013
    Posts
    365

    Help with VB Script Compare and Update

    Good Morning All,

    1. Compare the sheet UPDATE and MASTER. If there are NEW values (based on ID column) then paste those to the end of the MASTER sheet. If there are items MISSING in UPDATE but are found in MASTER I want the ID value in MASTER to have an "x" put on the front of the value. IE - if the value in master was 1234 and the value is MISSING in UPDATE then the value in MASTER will now be "x1234".

    Now the master should contain all new values and all old values will be preserved with an "x" in front of the original number.

    2,. Now for those values where we added an "x" I want the values in the DASHBOARD sheet to be changed from 1234 to "x1234" so the INDEX lookup will find the new value.

    I am attaching 2 files. One is ORIGINAL before the script runs. The second is UPDATE which is the desired result AFTER the script runs.
    Attached Files Attached Files
    If answer helped you say Thanks by Add Reputation

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Help with VB Script Compare and Update

    Try
    Sub test()
        Dim a, i As Long, e, n As Long, dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        a = Sheets("update").Cells(1).CurrentRegion.Value
        For i = 2 To UBound(a, 1)
            dic(a(i, 4)) = Application.Index(a, i, 0)
        Next
        With Sheets("master").Cells(1).CurrentRegion
            a = .Value
            For i = 2 To UBound(a, 1)
                If dic.exists(a(i, 4)) Then
                    If dic(a(i, 4))(1) = "" Then
                        dic(a(i, 1)) = Empty
                        a(i, 1) = "x" & a(i, 1)
                    End If
                    dic.Remove a(i, 4)
                End If
            Next
            .Value = a
            For Each e In dic
                If IsArray(dic(e)) Then
                    n = n + 1
                    .Rows(.Rows.Count + n).Value = dic(e)
                    dic.Remove e
                End If
            Next
        End With
        If dic.Count = 0 Then Exit Sub
        With Sheets("dashboard").[a2].CurrentRegion
            For i = 2 To UBound(a, 1)
                If dic.exists(.Cells(i, 4).Value) Then .Cells(i, 4).Value = "x" & .Cells(i, 4).Value
            Next
        End With
    End Sub

+ 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. Using a script to compare and delete columns
    By uomoeman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-30-2014, 02:28 PM
  2. [SOLVED] VB script to compare text, if not available do something else
    By Dexday in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 01:01 AM
  3. Update Script
    By mossman65 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2011, 10:55 AM
  4. Compare and copy cells script
    By fuchetj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2011, 08:52 AM
  5. VBA script to compare New and Old Budgets
    By cfo@k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2010, 11:30 PM
  6. Compare Data Script To check Names
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2008, 11:37 AM
  7. Update a workbook from a script
    By erich.haberman@gmail.com in forum Excel General
    Replies: 1
    Last Post: 03-08-2006, 10:35 AM

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