+ Reply to Thread
Results 1 to 20 of 20

Macro that copies based on cell value

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Macro that copies based on cell value

    I have 5 opened files. I have copied into those files a set of formulas from my master sheet (with the macro). In A3 of ALL the open files, there is a date (ex. Date: 1/4/2014) Based on that date I want to copy the result of what I copied into the files (below is the code that I used to copy into the open files, maybe I could add something to create a named range of the resulting paste) back into the master sheet into a tab called 2014 and into a cell two cells below the cell in row 12 with the MATCHING date. Please help!!



    Please Login or Register  to view this content.

  2. #2
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Hey there,

    Well, you can easily achieve this by introducing another IF condition inside that IF condition within the loop. Below is the modified version of your code:

    Please Login or Register  to view this content.
    Attached is a working sample for your reference.
    Attached Files Attached Files
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  3. #3
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    I don't think you are understanding me. I want to copy and paste a range of (formulas) into ALL of the five sheets that I have open. The formula that I have above works fine for doing that. When I'm done with that, I want to copy the result of the formulas (they are lookups) and paste special values back into the master tab, into a sheet called "2014". Each of the open workbooks has a date in A3. In the master workbook, in row 14, there are sequential dates. I want to copy the range that I copied into the open workbooks (the lookups) and copy this back into the master file "2014" tab, BASED on the dates in A3 of the open files. So, the macro will look at that row, match it (there will always be a match) and copy the range two cells below row 14. Make sense?

  4. #4
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    I've attached an example of what I want in a spreadsheet. The first sheet is one of the open files and the second tab is the tab in the master file that I want to copy to. Hope this helps.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    I also noticed that the code in my first post that I used was incorrect. It's actually this.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    Helloooooo. Nobody can help with this one? It seems like a fairly easy code.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro that copies based on cell value

    Hey - don't get pushy, we all work for free. You may be getting what you pay for.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro that copies based on cell value

    Hey freshfruit,

    The file you attached has no macro in it. If you attach a sample that has the data in sheet 1 and the macro, I can comment the code and see if I can figure it out. No guarantees though as I work for free.

  9. #9
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    What? I don't have a macro!! I NEED a macro. Instructions again:

    In the attached sheet, there is a tab called "Data sheet". This represents all of the open workbooks. In A3 there is a date, match this date to the dates in row 3, workbook and tab "2014masterfile" and copy the content starting in row 7 below the date in 2014 masterfile.

  10. #10
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Hello there,

    Am sorry for my late response. I've been caught up with some work at my office for past a few days. Well, to cater your needs. Am attaching a sample work again. Test it. I've not been very elaborative last time so have included instructions and a tutorial of how I did the same task. Check and let me know if things work out for you.. All the best!

    Tutorial Link
    Attached Files Attached Files

  11. #11
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Also, looking at your file, it seems you've additional parts in that date cell A3, i.e., it starts with an extra 5 letters ("Date: ") in the beginning of the value. If that's the case, then attached is the re-worked file which can be of use.

    Do let me know if things don't work out the way you wanted.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    Hey, codeslizer!! Thanks. Would you mind uploading the file as a regular file and not a zip? I can't open zips on my computer

  13. #13
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Sure, no problem.

    The Workbook files having string - "With Date" are files that work together and those without "With Dates" work together. Use either of them based on your requirements.

    Let me know if things don't really work out.

    Warm regards,
    cOdEsLiZeR
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    Also, there is an error in the code It doesn't run.

  15. #15
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Yeah.. I observed some inconsistencies when I opened more than one file. Thanks for the heads up. I fixed it, try it now.
    Attached Files Attached Files

  16. #16
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Macro that copies based on cell value

    What? I don't have a macro!! I NEED a macro. Instructions again:

    In the attached sheet, there is a tab called "Data sheet". This represents all of the open workbooks. In A3 there is a date, match this date to the dates in row 3, workbook and tab "2014masterfile" and copy the content starting in row 7 below the date in 2014 masterfile.
    you need to remember this is not a forum to provide you a shrink wrapped solution, it is designed to help you solve your problem

    see post #7 for another response

    consider yourself very lucky that @ codeslizer has bothered to respond

  17. #17
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    Still didn't work . Why do you have multiple files of the same thing?

  18. #18
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that copies based on cell value

    Freshfruit, are you following my instructions? There are two files to indicate two different scenarios in which date could come. My idea was simple "m/d/yyyy" format but when I went through your sample, it has a string part - "Date: " followed by a date in "m/d/yyyy" format. So, I have included both the files for your references as both of them takes care of the work in two different scenarios.

    You say it still doesn't work for you. How are you testing them? For my examples, you'll have to open main XL file along with its supporting document. Say like if you are opening
    1. "Check Date and Copy (With Date).xlsb" - main file then you'll also have to open "Workbook1(With Date).xlsx" - supporting file to check its working.
    2. "Check Date and Copy.xlsb" - main file then you'll also have to open "Workbook1.xlsx" and "Workbook2.xlsx" - supporting files to check its working.

    For a visual reference, I've also attached a GIF tutorial for "Check Date and Copy.xlsb" - main file in my earlier post.

    I hope you're not trying these main files with your XL files. The XL files that we provide here is just for ideas and references to make OP understand how they can work out in their XL challenges.

  19. #19
    Registered User
    Join Date
    01-22-2014
    Location
    Compton, whup whup
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Macro that copies based on cell value

    Hey Codeslizer. Thanks for all your help. This is reaaaaaally close. This is what is wrong: The formula gets pasted into ALL workbooks regardless of the date (so their should be no check n copy). Other than that, the code is perfect. I just need to figure out how to eliminate the check n copy and KEEP the code that relates to copying the values into the master sheet by matching the dates. Make sense?

  20. #20
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Macro that copies based on cell value

    Quote Originally Posted by freshfruit View Post
    What? I don't have a macro!! I NEED a macro. Instructions again:

    In the attached sheet, there is a tab called "Data sheet". This represents all of the open workbooks. In A3 there is a date, match this date to the dates in row 3, workbook and tab "2014masterfile" and copy the content starting in row 7 below the date in 2014 masterfile.
    Just a warning!!

    Common courtesy is the order of the day. Avoid coarse language, personal attacks and inflammatory remarks. Address your concerns at topics and not at people.

    User names that are deemed offensive or in poor taste are subject to being changed or banned.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ 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. [SOLVED] Wirte macro that copies data from 1 cell to a different cell based on data in a third cell
    By Geoff Jones in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-11-2013, 12:37 PM
  2. Macro thats copies data based on 2 variables.
    By dwilkinson12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2013, 10:34 AM
  3. [SOLVED] Macro that removes rows based on frequency and copies part of the row to a new sheet
    By njmiller31 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-28-2012, 05:32 PM
  4. [SOLVED] Macro which copies based on row and column inputs
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2012, 07:23 PM
  5. [SOLVED] macro which copies all column values based on specific string inputs
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-12-2012, 03:08 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