+ Reply to Thread
Results 1 to 10 of 10

Find if cell value is in range of other workbook and if true, copy-paste an offset cell

  1. #1
    Registered User
    Join Date
    01-16-2019
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    5

    Find if cell value is in range of other workbook and if true, copy-paste an offset cell

    Hi there ExcelForum community!
    It's my first post, don't be harsh if I do something incorrectly, I am still new to VBA

    I am trying to create a macro to help out with the daily workload at work, but due to various office policy, I cannot visit this at work (most websites are blocked at work ), neither can I download any files at work from the desktop.

    Therefore I can't really copy paste the stuff I already have, unless I'm to re-write it from scracth at home completly. Truth to be told, I don't have much because this macro is too challenging for a newb like myself, so I am counting on some help


    Description:

    We have two files.
    First file is called "DailyWorkload", consisting of 1 sheet only, called "Sheet1".
    Inside we have a variable number of rows (between 50 to 300 usually, but let's keep it defined as variable, to keep the code flexible in case there is a bigger workload).
    First row is column headers. There are 4 columns. Column D is "CountryVendor"

    Second file is called "Exceptions List". It consists of multiple sheets, however the data which will be used is located specifically in sheet "VendorsList".
    On VendorsList sheet, we have a list of vendors. Vendor names are concatenated with the country, because same vendors might be present in more than one country and have different exceptions to follow in every country). The "CountryVendor" name is in column G.
    Please note that new exceptions can be added to this file, therefore the range with the CountryVendor values to be compared to, should also be flexible, starting from row 2 until last row.


    Goal of the macro:
    I want the macro to check every vendor ("countryVendor") in the DailyWorkload and see if there is an existing exception for this "countryVendor" in the Exceptions List file. If yes, the description of the exception should be copied from Exceptions List and pasted into Daily Workload file. If the exception for the "CountryVendor" doesn't exist, then delete the row. Which means that at the end of the macro, in the Daily Workload file we should only see the rows with "CountryVendors" that have an existing exceptions.



    How I wanted it to work, so far according to my plan:

    Define range1 in DailyWorkload, in column D, as cells from row 2 until last row (CountryVendors list for that particular day).
    Define range2 in ExceptionsFile (sheet VendorsList) from cell G2 until last row (so the list of all CountryVendor exceptions input in the file)
    Then, starting from the end of the range1, going upwards, for every cell in range1, find if the value is present (matches/equals) anywhere in range2.
    If No (meaning this country/vendor combination has no exceptions), then delete the row in DailyWorkload file.


    If yes (there is an existing excpetion written down for this country/vendor combiation), then copy the description of this exception (under column E) from the "Exception List" (sheet" VendorsList") file, into the DailyWorkload file under column F


    Now what I am stuck at (or what I suck at), is the proper definition of those two ranges, because they are in different workbooks and I can't seem to define it properly and loop it correctly. S



    Additional question (more of a theoretical question on how you'd solve it): what if a vendor has two exceptions in the same country? Obviously those exceptions can be just combined in one huge cell with lots of text. But What if someone, by accident, enters second exception for the same CountryVendor combination, or just enters a duplicate? How would the macro behave in such situation?
    Is there any smart way?
    What I thought about, is that instead of copy-pasting the description from one book into the other, we'd just copy the UnqiueID of the Exception (columnA), into column F on the DailyWorkload workbook, in such way that it should be more than 1 value . Like let's say IrelandGoogleInc has 3 exceptions, UniqueIDs: 5, 210,211. So then macroo, when searching for "IrelandGoogleInc" value in the range2, would find it 3 times and would past this in column F: 5;210;211. The employee would know which Exceptions to check for this vendor.

    Anyway, I know it's a heck of a big ask, but if anyone can help me out, I'd be really happy.
    I tried to describe it as best I could, I do realise that without any basic tables and examples it might look a bit abstract, but if you need to ask any more specifics, I will be happy to provide them

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Make sure that both workbooks are open. Place this macro in a standard module in your "DailyWorkload" workbook. Save the workbook as a macro-enabled file. Run the macro with Sheet1 as the active sheet. I have assumed that the Exceptions List file has an "xlsx" extension (in red). Change it to suit your needs.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-16-2019
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    5

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Hey Mumps1, thanks for replying!
    sorry, I forgot to mentioned one thing: the macro will be placed in a third file, in which we have all other macro-related tools and buttons.
    Could you modify the code to work on the both files, while the macro is started by clicking button in the third file?
    Would be good if the "ExceptionsFile" and "DailyWorkload" are opened automatically by the macro. You can use a generic filepath, I will manage to adjust it later on to route to those two specific files.
    Also, "Exceptions File" is a macro-enabled format file, in case that needs to be taken under consideration.


    However, I did try to run your code, slightly adjusted and it worked really nice ! : )
    I was surprised to see it works so effectively with such short code.

    The only thing I'd need now is to adjust it to be started from a third file, and work on the two files in the background.
    Last edited by Szechter; 01-17-2019 at 11:20 AM.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Are the ExceptionsFile and DailyWorkload files saved in the same folder as the third file containing the macros? If not, what is the full path to the folder containing the two files? Do both files have an "xlsx" extension?

  5. #5
    Registered User
    Join Date
    01-16-2019
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    5

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    ExceptionsFile will be put on the desktop and it is macro enabled file
    DailyWorkload is located under H:\Desktop\Productivity (it is xlsx file)
    ThirdFile (called "MacroSupport") is located on the desktop as well

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Is the computer you are using configured with the Desktop on the H:\ drive or on the C:\ drive?

  7. #7
    Registered User
    Join Date
    01-16-2019
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    5

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    It's on H drive. Other macros work without any issues when I set the filepath as H:\Desktop\Productivity or other folders

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Try:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-16-2019
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    5

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    Mumps, big thanks! Everything works perfectly, after some minor adjustments !
    It's really gonna have a positive impact at the workload for all employees.

    Thanks again !!

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Find if cell value is in range of other workbook and if true, copy-paste an offset cel

    You are very welcome.

+ 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. Copy range to existing workbook and paste with an offset
    By windowshopr in forum Excel General
    Replies: 1
    Last Post: 04-16-2014, 11:39 AM
  2. VBA code to copy cell formats and paste using offset for Rows/Range
    By spenlinhauer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 07:45 PM
  3. Replies: 1
    Last Post: 02-04-2014, 01:57 PM
  4. Find Cell Value in Workbook; Paste Cell Range When Found
    By bbarber71389 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2014, 04:18 PM
  5. Replies: 1
    Last Post: 01-03-2014, 03:01 AM
  6. Loop to find a cell, then copy offset paste
    By mr.alexander in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-29-2013, 08:48 AM
  7. Find the specific text and copy and paste in another cell only if true.
    By SHARIB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2012, 03:14 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