Consulting

Results 1 to 11 of 11

Thread: Solved: calculate difference between 2 excel files

  1. #1

    Solved: calculate difference between 2 excel files

    Dears,

    I need your help..
    I’ve daily data consists of many rows and columns..
    I’d like to have macro to calculate difference between Today Excel and Yesterday Excel based on column D
    I can do vlookup to get equivalent data from Yesterday excel into Today excel based on column D, then calculate the difference
    But doing that for large amount of data and dynamic as Excel template itself may be could change in the near future is forcing me to search for smart solution “dynamic macro”..
    So kindly advice how to do that..

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you can post a small sample of typical data on two sheets and show the result you are after, it would assist.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    here it is..
    Thanks in advance

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    How should the resulting sheet look?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    it will be highly appreciated if the result will be as shown in below attachement:

    - all columns with colored header to be contains Delta values "Difference between Today data & yetserday Data"


  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With both books open, run the following macro in the Today book

    [vba]
    Option Explicit

    Sub CompareData()

    Dim Ths As String
    Dim LstBk As String
    Dim LstSht As String
    Dim Fmla As String
    Dim txt
    Dim Rng As Range


    Sheets(1).Copy After:=Sheets(1)
    Sheets(2).Name = "Results"

    With Sheets(2)
    Set Rng = Range(.Cells(2, 1), .Cells(Rows.Count, 1).End(xlUp))
    End With
    Set Rng = Rng.Offset(, 4).Resize(, 36)
    Rng.ClearContents

    Ths = Sheets(1).Name
    LstBk = InputBox("Previous book name", , "Worst Cell List_Final_15.xlsx")
    LstSht = InputBox("Previous sheet name", , "Worst cell list_15")

    Fmla = "='ThsBook'!RC-INDEX('[lstbook]lstsheet'!C,MATCH(RC4,'[lstbook]lstsheet'!C4,0))"
    Fmla = Application.Substitute(Fmla, "ThsBook", Ths)
    Fmla = Application.Substitute(Fmla, "lstbook", LstBk)
    Fmla = Application.Substitute(Fmla, "lstsheet", LstSht)

    Rng.FormulaR1C1 = Fmla

    End Sub[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Amaaaaaaaaazing

  8. #8
    Dears,

    kindly advice how to delete above attachments..

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I have deleted the attachments.

    Thanks

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi JustDream,
    Can you please reposrt a sanitised workbook to make the solution meaningful to others.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Dear mdmackillop,
    For sure, here's another workbook to be used by others as draft data
    Dear VBAexpress users, before using mdmackillop's code using my new attached data
    just change line no. 14 to have that simple modification

    [VBA]
    Set Rng = Rng.Offset(, 4).Resize(, 3)
    [/VBA]
    Attached Files Attached Files

Posting Permissions

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