+ Reply to Thread
Results 1 to 8 of 8

Excel VBA - Import File and Compare Sheets

  1. #1
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Excel VBA - Import File and Compare Sheets

    Hi all, I'm fighting my way to create a file for reporting purposes.

    The file itself is a spreadsheet that Imports an Excel file (lets call it RAW) with a list of items and categories into the report file (BASE)
    BASE file got several sheet one for each RAW category, and a additional sheet with the addition or removal of items for each category.

    I did my homework and figured out how to import and extract the data from the RAW into BASE on a temp sheet.

    Now I'm struggling to do the previously stated.
    My logic says that procedure should be as follow:

    1. Import File
    2. Read RAW data
    2.a. Compare RAW data item/category with BASE item/category sheet.
    2.b. If RAW item/category exist on BASE item/category sheet = do nothing
    2.c. If RAW item/category not on BASE item/category sheet = add it to BASE item/category sheet and into BASE Tracking sheet as NEW
    2.d. If RAW item/category not on RAW but in BASE item/category sheet = remove it from BASE item/category sheet and add into BASE Tracking sheet as REMOVE
    3. Redo (2) next sheet
    4. Close

    I don't want to put any of you into the trouble of saving me this for me, but just an idea will do the trick.

    Thanks in advance for any idea!
    Attached Files Attached Files
    Last edited by tanomandanga; 11-24-2017 at 12:15 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Excel VBA - Import File and Compare Sheets

    The "sketch of algorithm" presented seems legit. The only poind I'd see quite different is sheets to be removed from BASE.
    I'd do this in a separate loop
    so:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Re: Excel VBA - Import File and Compare Sheets

    Please Login or Register  to view this content.
    Issues so far are not being able to change from worksheet based upon cell value. And working out the compare process between the ExtractReport range and the destination range.
    Last edited by tanomandanga; 12-07-2017 at 09:13 AM.

  4. #4
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Re: Excel VBA - Import File and Compare Sheets

    I've making some changes and reached out this far... alone, which is nice
    Although some help might be needed...

    Please Login or Register  to view this content.
    The code reads each row and goes to the sheetname based on cell value. Compares rawName cell value with sheetname cell value. If is not present, its copies B:J from rawName to C:K in sheetname and adds an "Added" value to last column L for reference purposes.

    Aside the obvious, one of the issues is that lastrow on rawName is different than lastrow on each strName

    Any ideas?

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Excel VBA - Import File and Compare Sheets

    In your ranges you start from some cell and end in ... cell in active sheet.
    How about:
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Re: Excel VBA - Import File and Compare Sheets

    Thanks for the tip, it helps on selecting the right sheet however its still causing issues

    The rawName sheet contains 2k rows, which contains devices that are or will be stored in the other 5 different sheets.
    When I run the code it shows the 2k-ish rows that are stored in the rawName.range and then for each strName sheet shows 1048576 rows, instead of the 800 or 300, or 20 rows that each different sheet has.

    Also I'm experiencing an issue when copying the values on "c.Range("B" & i & ":J" & i).Copy" its only retrieving rows E:J
    Tried to change it to:
    Please Login or Register  to view this content.
    With no luck at all...

    File is attached for a little more in depth approach
    Thanks again for the assistance!

    Excel file

  7. #7
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Re: Excel VBA - Import File and Compare Sheets

    Hello folks,

    I'm still working on this, I was able to figured out the addition of new items and went all the way thru to items being removed and a tracker process.

    However rows are now being duplicated and not properly updating (on either adding or removing process).
    I've hardcoded the worksheet.count to avoid working outside the range, but still getting issues with others sheets of the same workbook

    This is the code for the items being added, the idea behind this is that each sheet name is stored in a column of rawName then reading and cycling thru each row and each sheet, reviewing values from rawName towards the other sheets, if missing then copied and labeled as added.
    Please Login or Register  to view this content.
    This is for the items being removed, same as before, sort of reverse engineering all sheets values againts rawName, if missing then labeled as removed.


    Please Login or Register  to view this content.
    And this is the comparison process that reads all L column values, copy the row and removes when required.
    Cycling thru sheets, reviewing L column values from sheets 4 to 8 that excludes rawdata and 2 more sheets.
    If any "Added" value is found the cells are copied and arranged to the tracker, and the label is cleared.
    If any "Removed" is found, then as before the information is copied and the entire row is deleted from source sheet
    Please Login or Register  to view this content.
    Attached is the current work file, with dummy values on all sheets, which after I run the process that calls all subs, several rows get duplicated by the end of it.
    I know this is not rocket science, but maybe a fresh look will help me see thru the issues.

    Work, Updated File

    Thanks in advance for any tip! And as always, sorry for the trouble...

  8. #8
    Registered User
    Join Date
    12-29-2016
    Location
    Tatooine
    MS-Off Ver
    2016
    Posts
    9

    Re: Excel VBA - Import File and Compare Sheets

    Sadly I'm having a code that works partially ok, meaning that the code reads and is able to copy some of the needed rows.

    Please see code below
    Please Login or Register  to view this content.
    This code will read the rows being added from NIKE towards the rest of the workbook and add them if not present, afterwards I will copy them to the tracker sheet (Currently adding all to their respective sheet but not copying'em all to the tracker sheet)

    And below is the opposite code..

    Please Login or Register  to view this content.
    This one will do it backwards, comparing the currently existing rows and if any of them is not present in NIKE sheet will remove it from its current sheet and copy to the tracker sheet. (This is almost not working at all... dunno why!)

+ 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. import txt file into separate excel sheets and look for a specific row to add
    By tuspilica in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2017, 02:58 PM
  2. [SOLVED] Import Multiple Sheets from one file
    By capson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-14-2015, 07:36 PM
  3. Import Multiple Sheets from one file
    By capson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-14-2015, 11:04 AM
  4. Help with Macro to compare two sheets in Excel File.
    By SamCV in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-23-2015, 01:08 PM
  5. Import text file into excel and split data in specific sheets
    By chirilaionut in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-03-2013, 07:04 AM
  6. Import file - compare two lists
    By theta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2011, 08:54 AM

Tags for this Thread

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