+ Reply to Thread
Results 1 to 21 of 21

VBA Code for populating cells from one Work Book A to another Work Book with condition

  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    VBA Code for populating cells from one Work Book A to another Work Book with condition

    Hi,

    I don't know much about VBA but know that VBA is an extremely rich programming language.
    It will be great if someone help me and write a code to solve my problem.

    I have 2 Excel workbooks ( A and B) at different locations.
    Excel workbook A has "Master Sheet" having unapproved projects list and workbook B has three sheets (Yes_Sheet, No_Sheet, Hold_Sheet)
    Both workbooks have same type of tables with same format(Please see attached workbooks)
    The only difference is that in workbook A there is an extra column (heading: Decision) with drop down list (Yes, No, Hold)

    What I want:
    1- when we select "Yes" from drop-down list under Decision heading in Master sheet of workbook A, it should transfer all data (from "Project Name" to Column 10 except Column 2 and Column 4) of first project from "Master Sheet" in workbook A to Yes_Sheet in workbook B.

    2- when we select "No" from drop-down list under Decision heading in Master sheet of workbook A, it should transfer all data (from "Project Name" to Column 10 except Column 5 and Column 9) of first project from "Master Sheet" in workbook A to Yes_Sheet in workbook B.

    3- when we select "Hold" from drop-down list under Decision heading in Master sheet of workbook A, it should transfer all data (from "Project Name" to Column 10 except Column 5 and Column 9) of first project from "Master Sheet" in workbook A to Yes_Sheet in workbook B.


    Each time when we select any one option from drop down list (Under Decision field in Master_Sheet of workbook A), it should transfer/populate the project data in next available row of required sheet (Yes_Sheet, No_Sheet, Hold_Sheet) of workbook B.

    I would like to thank you all in advance.

    Thanks
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Shouldnt step 2 copy to Wb-B NO sheet?
    and
    step 3 copy to Wb-B HOLD sheet?

  3. #3
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    IF this is true (what i posted above), then enter the VBE screen,
    in the right project screen, in the VBAProject of your MASTER workbook,
    dbl-click on ThisWorkbook,
    on the code screen, paste this code:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Thanks Ranman256! I really appreciate your time......

    I tested and it's giving me error.
    See attached screenshotError.JPG
    Last edited by ray.kanata; 06-11-2015 at 01:21 PM. Reason: Forgot to attach file

  5. #5
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Still waiting....
    Attached Images Attached Images
    Last edited by ray.kanata; 06-11-2015 at 02:35 PM.

  6. #6
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    hmm, its possible that you dont have it open.
    or
    just type in the full name instead of variable
    Workbooks("WorkBook_B.xls")
    or is it .xlsx?

  7. #7
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Hi Ranman256!

    You are excellent in VBA
    Now I understand the error.
    It worked with: Workbooks(kBwb & ".xlsx")

    It will be great if it copy when Workbook_B is closed.....Is it possible???

    Thanks for your time

  8. #8
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    no, you cant write anything to a file unless its open.

  9. #9
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Thanks!

    I just notice that it also copy the drop down list.
    I don't want to copy that drop down list from Workbook_A as it is just for decision in Master Sheet of Workbook_A.
    See attached

    Once again thanks for all you help

  10. #10
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Thank you very much Ranman256!

    It's solved

  11. #11
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Hi Ranman256!

    Why my VBA Code keeps disappearing ?

    I have a code that auto save file in xlsm in another location but the above code in "Thisworkbook" keep disappearing.

    Hope you can help me

    Thanks

  12. #12
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Hi Ranman256!

    Yes, I also tried to use the same code in particular sheet instead of pasting in "Thisworkbook", it didn't work.
    is there anyway I can use same code in specific sheet.

    thanks

  13. #13
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    It's working fine but I want the code in master data sheet in workbook_A

    Thanks

    Code with files attached:

    WorkBook_A.xlsmWorkBook_B.xlsx

  14. #14
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    WorkBook_A.xls

    update working for me.

  15. #15
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    REMEMBER, you cant save vb code in a XLSX file. IT MUST BE .xls , OR .xlsm

  16. #16
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Thanks Ranman256! I appreciate ur care and time...Sorry I couldn't explain well

    You are right it's working fine but whenever I save it to another location by using "save as" it disappears. I am thinking that if this code is pasted in Master Sheet of workbook A, it (code) will be not disappear.

    See what I want in pic attached
    What I want.JPG

  17. #17
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Thanks Ranman256! I appreciate ur care and time...Sorry I couldn't explain well

    You are right it's working fine but whenever I save it to another location by using "save as" it disappears. I am thinking that if this code is pasted in Master Sheet of workbook A, it (code) will be not disappear.

    See what I want in pic attached
    Attachment 401453

  18. #18
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    are you saving it as .XLS?

  19. #19
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Nop! I am saving as .XLSM

    I was thinking if we paste the same code in "Master Sheet" of Workbook_A instead of "Thisworkbook" of Workbook_A, it will solve the problem.
    My problem is I don't know how to modify the current VB code for "Master Sheet", so it should work same but pasted in "Master Sheet".

    Can you modify it plz?

    Thanks

  20. #20
    Registered User
    Join Date
    12-12-2013
    Location
    Sudbury
    MS-Off Ver
    Excel 2010
    Posts
    66

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    Plz see attached file.WorkBook_A (3).xlsm

  21. #21
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: VBA Code for populating cells from one Work Book A to another Work Book with condition

    There is NO CODE in this wb. I pasted and it works fine.
    WorkBook_A (3).xlsm

    It doesnt matter what the workbook is named,
    nor what the sheet is named.
    The code MUST be put in THISWORKBOOK.

+ 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. Work book link to other work book
    By Mjh35 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-08-2014, 03:55 AM
  2. Replies: 2
    Last Post: 06-20-2012, 05:10 AM
  3. [SOLVED] Populating Textbox base on Combobox value from another work book
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 04:17 AM
  4. Creating auto populating Summary sheet as new sheets are added to work book
    By Phraedrique in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-18-2012, 05:01 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