+ Reply to Thread
Results 1 to 30 of 30

Copy and transfer data from a Main sheet to two sheets based on two conditions

  1. #1
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Copy and transfer data from a Main sheet to two sheets based on two conditions

    Hi everyone
    I have attached the following example " TEST" to make it more clear
    It is excellent but very slow in dealing with large data so I need a faster solution using arrays If possible
    I have data starting at row 8
    I need to Copy and transfer data from a Main sheet to two sheets based on two conditions
    For example
    In Main sheet the column No. 31 the word "Yes" I want to copy columns from 1 : 5 with columns from 33 : 36
    depending on the 31 column and transferred them to the " yes" sheet
    and In Main sheet the column No. 32 the word "no" I want to copy columns from 1 : 5 with columns from 37 : 40
    depending on the 32 column and transferred them to the " no" sheet
    This has been achieved in the attached file "TEST2"
    I need to insert six rows after each 30 names in two sheets (yes & no)
    These rows will serve as totals and footer.
    I have highlighted the points where I would like to insert the rows
    if the remain items is less than 30 then to insert rows directly after them
    During that process I would like to add some strings in these inserted lines
    in the first inserted row To create the totals formulas and the formatting
    in the second inserted row type : "Signature" in column B and in column D: "Signature" and in column H: "Signature"
    in the third inserted row type : "Auditor" in column B and in column D: "Head of Accounts" and in column H: "General Manager"
    in the six inserted row To create the previous totals and the formatting
    With adjust the vertical and horizontal page breaks automatically
    I hope the idea is clear and I hope a solution using arrays
    The expected result in the two sheets result1 and result2
    Please have a look at the examples
    Your help is greatly appreciated
    Thanks in advance
    Attached Files Attached Files
    Last edited by Joky; 07-09-2017 at 11:16 AM.

  2. #2
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Your help is greatly appreciated

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    A faster alternative without using arrays:
    - I have not used arrays but I expect that you may find that this solution is quicker than your current one
    - You can test in the attached workbook with {CTRL} q
    - I added lots of duplicate rows to Data Source to allow fuller testing
    - headers not added in row 1
    - total font has not been made bold
    - no merged cells - avoid them when you want to use VBA - they cause too many problems
    - TestNo duplicated from TestYes (I was too lazy to write a code to avoid the duplication )

    How it works:
    - DataFilter used on sheet source - filter for YES or NO
    - copy all filtered rows together to other sheet (copy ALL columns)
    - then delete columns not required
    - insert the 6 rows
    - add totals etc

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 07-10-2017 at 02:33 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Hello Mr. kev
    Thanks a lot for your patience in this issue
    In fact your solution is very very excellent and big step towards the ultimate aim
    Give me some time to work on the original file and I will tell you about any notes
    Best and kind regards

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    @ Kev - I'm especially interested in the page breaks - have you already addressed them in your code?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    @Xladept - my solution has not yet gone that far. Wanted to offer OP alternative to arrays ..
    Last edited by kev_; 07-10-2017 at 01:38 AM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    @Joky

    Please consider these suggestions for your page layout
    1 Do you need the empty rows at top of page 1
    2 Signatures better laid out one under the other (see picture) - can double row height to provide more space
    3 You do not need to use merged cells to get the look you want
    - they are best avoided because they are very inflexible and are a nuisance if you want to alter things later


    Layout.jpg

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    @xladept

    @ Kev - I'm especially interested in the page breaks
    Generic code for page breaks every "X" rows (- here set to 36 as per OP example)

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. xladept
    You've helped me for days in the same issue
    Sure it would be easier for you to adapt it to the new issue
    I would like to see your solution and I am sure it will be great
    Best Regards

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Hi Kev,

    Thanks for that, I tried something similar but it didn't work on my 2010 - do you have code for the vertical break??

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    @xladept

    This works with both 2010 and 2016

    Please Login or Register  to view this content.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    This is what I had to do before it worked:

    Please Login or Register  to view this content.
    And, I had to be in page break view to get the HBreaks

  13. #13
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. kev
    Just I need to refer to some points
    - Add a line to not copy and transfer data if one of the two conditions is not met or the two conditions are not met
    - I need to inserted footer rows without borders
    - adjust the vertical and horizontal page breaks automatically
    - adjust the height of the total row and the row height of the previous total ...I need to customize the high rows
    - adjust the formatting of the footer rows…. I need to customize the font type and size, as well as the high rows
    - an order to print the workbook automatically
    As for your notes
    - for the first five rows, it is for the company name, address, etc.
    - There should be a headers for columns in rows No. 6 & 7 to specify their titles
    As for the merged cells Please have a look at The basis of the idea in my attempts
    Your help is greatly appreciated
    Thanks in advance

  14. #14
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Your help is greatly appreciated

  15. #15
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    That was your second "bump" posted within a few hours of your own previous post
    bump 1 = 14 hours (post#02)
    bump 2 = 10.5 hours (post#14)

    bump2 puts you at the bottom of the queue

  16. #16
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. kev
    The problem is that the original file contains many interconnected papers so it took a lot of time until I finished it
    Anyway You should be honest with you... your solution is very very excellent
    I need to adjust the points referred in your code only
    Thanks advanced for help
    Regards
    Last edited by Joky; 07-11-2017 at 06:40 AM.

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    I will try to get back to your thread later today

    What does this mean?
    Add a line to not copy and transfer data if one of the two conditions is not met or the two conditions are not met
    Does it mean copy only if column 30 = YES AND column 31 = NO


    31 = YES
    32 = NO
    COPY to sheet YES and sheet NO

    31 = (empty)
    32 = NO
    DO NOT COPY

    31 = YES
    32 = (empty)
    DO NOT COPY


    31 = (empty)
    32 = (empty)
    DO NOT COPY

  18. #18
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. kev
    I mean
    31 = YES
    32 = NO
    COPY to sheet YES and sheet NO

    31 = (empty)
    32 = NO
    COPY to sheet NO

    31 = YES
    32 = (empty)
    COPY to sheet YES

    31 = (empty)
    32 = (empty)
    DO NOT COPY

    Regards

  19. #19
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Is that not the same as....?

    If 31 = YES copy to sheet YES

    IF 32 = NO copy to sheet NO

  20. #20
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. kev
    If cells the column number 31 and the column number 32 = empty do not copy
    If any cell in column 31 = yes Copy to sheet YES
    If any cell in column 31 = empty no Copy in sheet YES
    If any cell in column 32 = no Copy to sheet NO
    If any cell in column 32 = empty no Copy in sheet NO
    Regards
    Last edited by Joky; 07-11-2017 at 11:25 AM.

  21. #21
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Again I repeat. These are the only conditions required:
    IF 31 = YES copy to sheet YES
    IF 32 = NO copy to sheet NO
    Everything else is irrelevant
    If I am incorrect, you need to amend data filter conditions

    - If you choose to amend anything you will need to do the same for both TestYes and TestNo
    - Row 1 is the header row repeated at top of every sheet
    - I was not sure what to do with first 5 rows so I ignored this and left top of sheet without blank rows - you can amend code to suit- yourself (- but remember Row 1 is the header row repeated at top of every sheet)
    - Total rows row height now 30 and font is bold
    - Borders put around around all values
    - Borders removed in signature area - you may want to increase the height of these rows
    - Page breaks inserted every 36 rows
    - No merged cells introduced - create them yourself if you want them
    - You need to amend the array containing Headers1 to 9 - simply type the headers in " " separated with a comma (both macros)

    Attached is PDF showing results
    Attached is workbook with working code
    Run macro Test which runs TestYes and TestNo

    I am away from my computer for 7 days - so I cannot help you until then

    This is TestYes - TestNo is exactly the same except where references are to sheet "NO" and column 30
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 07-11-2017 at 12:27 PM.

  22. #22
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Headers at top of page

    If you want row 6 to be the headers and rows 1 to 5 to contain other information printed on every page then (for both macros):
    1 delete this line
    Please Login or Register  to view this content.
    2 add code for what you need in rows 1 to 5

    3 change this
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    4 change this
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

    The code to print automatically
    Please Login or Register  to view this content.
    Last edited by kev_; 07-11-2017 at 12:24 PM.

  23. #23
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot for reply Mr. kev
    I have tested this great code ... That's really wonderful solution
    In fact I've learned a lot from you and will do my best to study this great code
    The last point is now for me
    During data copy, the data copy range remains selected
    Other than that I can work quietly
    To clarify .... Please have a look at the examples
    Regards
    Attached Files Attached Files
    Last edited by Joky; 07-11-2017 at 05:35 PM.

  24. #24
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    During data copy, the data copy range remains selected
    add this line after the paste:
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot Mr. kev for your patience and for great help all the time
    Thank you very very much for your great support in this issue
    I am just a learner and I have learned a lot and a lot from you
    The words are not enough to say thank you for you Mr. kev
    I also thank Mr. xladept for his great efforts from which I learned a lot
    Best Regards
    Last edited by Joky; 07-11-2017 at 06:23 PM.

  26. #26
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Mr. kev
    Thank you very very much for this great help
    Last edited by Joky; 07-13-2017 at 08:29 PM.

  27. #27
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Could do this at end of macro

    yes.Activate
    Range("A1").Select

    Just leaves cell A1 selected
    Same for other sheets

  28. #28
    Registered User
    Join Date
    06-23-2017
    Location
    Indonesia
    MS-Off Ver
    2007
    Posts
    67

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    Thanks a lot Mr. kev
    Thank you very very much
    Best Regards

  29. #29
    Registered User
    Join Date
    07-30-2017
    Location
    Poelkapelle, Belgium
    MS-Off Ver
    2016
    Posts
    5

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    I'd like to make an excel database for my hotel where there's a main sheets that shows: Room Number, Problem, Person who reported the problem, and problem solved or not. But then I'd also like to have seperate sheets for each room that shows everything on the main sheet corresponding with that room number. I don't know how I would go about setting it up so anything I type in the main page will automatically show up on its corresponding room sheet. Please Help, Thanks.

  30. #30
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy and transfer data from a Main sheet to two sheets based on two conditions

    This look like a new requirement

    It would be better to start a new thread with a new title "Excel database of Hotel Issues"
    Attach a sample file showing what is typed into main sheet and what you would like to see in corresponding room sheet

+ 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] Transfer data from one main sheet to two sheets
    By KingTamo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2016, 03:53 AM
  2. [SOLVED] Display data from sheets based on value in a cell on main sheet.. Help!
    By cpyter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-29-2014, 02:20 PM
  3. [SOLVED] Bulk import. (Copy Data from one sheet to a main sheet with conditions)
    By DanzaNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 12:24 AM
  4. Copy data from multiple sheets to one main based on cell value
    By jdjenterprises in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2013, 10:13 PM
  5. copy data from main sheet to respective sub sheets
    By sshanku1985 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-14-2011, 12:26 PM
  6. Macro to transfer data from main sheet to sub sheets
    By sandbach in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-02-2010, 05:42 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