+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 30

Thread: Is this type of copy even possible?

  1. #1
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Is this type of copy even possible?

    Trying to create a custom solution in Excel, and everybody in the office is stumped.

    The Excel document has three worksheets, called MASTER, DATA1, DATA2. All three worksheets have the same columns, in the same locations. Only thing different is DATA1 and DATA2 have different info listed in their rows.

    What we want to do is have the MASTER sheet display content from both DATA1 and DATA2. The trick is that data will be updated in DATA1 and DATA2 regularly, additional rows of content will be added over time.

    How do we get this type of content to properly display in the MASTER sheet? We need MASTER to be dynamic enough to "add" rows from DATA1 and DATA2, or even delete rows from either of those sheets...all without overwiting data from the other worksheet. We can "reserve" a number of rows in MASTER, but we'd like to have it list all the rows from one, then all the rows from the other, if at all possible.

    Help? Thank you!
    Last edited by klamen; 01-14-2010 at 10:24 AM.

  2. #2
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,288

    Re: Is this type of copy even possible?

    If you put all the data into MASTER you could then make some of it appear in DATA1 and some in DATA2, just by having an additional column in MASTER

    May be more practicable in the long term.

    CC

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,637

    Re: Is this type of copy even possible?

    You would need code to copy the data from each sheet to the master.Would you clear existing data from the incoming sheets or h=just keep adding them?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #4
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Is this type of copy even possible?

    Quote Originally Posted by royUK View Post
    You would need code to copy the data from each sheet to the master.Would you clear existing data from the incoming sheets or h=just keep adding them?
    The incoming sheets (DATA1 and DATA2) may have additional rows of content added over time, but the columns would never change in any of the worksheets. We would like to be able to delete rows of content if needed, but if that is not possible, we can color fill the data fields on the DATA sheets so on the MASTER it shows that those row issues are already resolved.

    We can "copy/paste" to MASTER, but with 20 employees accessing DATA1 and DATA2 (and perhaps more worksheets), somebody's going to forget to manually update the MASTER worksheet.

  5. #5
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Is this type of copy even possible?

    Here's the issue we have. If currently DATA1 has 5 rows of data, and DATA2 has 5 rows of data, it's easy to get that copied over automatically to MASTER. Problem is as soon as we add two rows of data to DATA1, it now has 7 rows of data to copy to MASTER. Now, this "overwrites" the data coming from DATA2 into MASTER, and none of it shows up.

    So, is there a way to automatically place an empty row in MASTER, that keeps the info from DATA1 an DATA2 separated? So if DATA1 has more rows added, it will simply go to MASTER (no matter how many rows are there), the "buffer empty row" is there, and then the data from DATA2 goes into MASTER? This would keep the data visible on Master, but not allow for additional rows in the DATA sheets to overwrite the other.

  6. #6
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,288

    Re: Is this type of copy even possible?

    Quote Originally Posted by royUK View Post
    You would need code to copy the data from each sheet to the master.
    Au contraire, my dear Roy.

    We could create a query to reference the other tables (we would need to name them) and use union (or union all) to append the two sheets' worth of data...

    Are you willing to try this, klamen? It takes a little while to explain and I don't want to waste my time!

    CC

  7. #7
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Is this type of copy even possible?

    I'm willing to try anything at this point, CC You would think this would be something very simple with a copy function, but guess nobody else at MS thinks consolidating info onto a master is important Thanks!

    By the way, I've got a test file with what I'm trying to do...just can't figure out how to get it attached here on my forum postings.

    EDIT: UPLOADED SAMPLE XLSX file
    Attached Files Attached Files
    Last edited by teylyn; 01-22-2010 at 04:39 PM. Reason: quote removed

  8. #8
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,288

    Re: Is this type of copy even possible?

    When you're editing a post, click "go advanced" and underneath the main edit window is a "manage attachments" area - use that. If you upload a nice simple example I will be able to walk you through the steps much more easily.

    CC

  9. #9
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Is this type of copy even possible?

    Thanks, edited my response above with the test document. All I want is to get everything from DATA 1 and 2 (and other future additional sheets) into MASTER, no matter how many rows there are in each of the sheets

    I do appreciate your helping me along!
    Last edited by teylyn; 01-22-2010 at 04:39 PM. Reason: quote removed

  10. #10
    Registered User
    Join Date
    05-20-2008
    Location
    England
    MS-Off Ver
    Office 2007
    Posts
    81

    Re: Is this type of copy even possible?

    Quote Originally Posted by Cheeky Charlie View Post
    Au contraire, my dear Roy.

    We could create a query to reference the other tables (we would need to name them) and use union (or union all) to append the two sheets' worth of data...

    Are you willing to try this, klamen? It takes a little while to explain and I don't want to waste my time!

    CC
    I would also be interested in learning this.

    Andrew

  11. #11
    Registered User
    Join Date
    01-14-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Is this type of copy even possible?

    Still looking for ideas.

  12. #12
    Forum Guru contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2010
    Posts
    1,342

    Smile Re: Is this type of copy even possible?

    Maybe it's not the best option but it works. I've uploaded workbook.

    Private Sub MasterButton_Click()
    Dim Db1, Db2 As Worksheet
    Dim MyDb1Rng, MyDb2Rng As Range
    Dim lRow, lstRow, lsRow As Long
    
    Set Db1 = Sheets("DATA1")
    Set Db2 = Sheets("DATA2")
    
    Application.ScreenUpdating = False
    
    'Finding last row in DATA1 sheet
        With Db1
            lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        End With
    
    'Finding last row in DATA2 sheet
        With Db2
            lsRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        End With
    
    'Finding lastrow in Master sheet
        With ActiveSheet
            lstRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        End With
        
    'Clearing Contents of used range in master sheet
    Sheets("Master").Range("A2", "H" & lstRow + 1).ClearContents
    
    'Setting up and copying DATA1 used range and pasting copied range into Master sheet.
    Set MyDb1Rng = Db1.Range("A2:H" & lRow)
        MyDb1Rng.Copy
        Sheets("Master").Range("A2").PasteSpecial (xlPasteValues)
        Application.CutCopyMode = False
    
    'Setting up and copying DATA2 used range and pasting copied range into Master sheet.
    Set MyDb2Rng = Db2.Range("A2:H" & lsRow)
        MyDb2Rng.Copy
    
        'Finding lastrow in Master sheet
        With ActiveSheet
            lstRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        End With
    
    Sheets("Master").Range("A" & lstRow + 1).PasteSpecial (xlPasteValues)
    
        With Application
            .CutCopyMode = False
            .ScreenUpdating = True
        End With
    End Sub
    Attached Files Attached Files
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, «Born in USSR»
    Vusal M Dadashev

    Baku, Azerbaijan

  13. #13
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,770

    Re: Is this type of copy even possible?

    Contaminated,

    In these declarations,
    Dim Db1, Db2 As Worksheet
    Dim MyDb1Rng, MyDb2Rng As Range
    Dim lRow, lstRow, lsRow As Long
    ... everything except the last variable on each line is a Variant. What you want is
    Dim Db1 As Worksheet, Db2 As Worksheet
    Dim MyDb1Rng  As Range, MyDb2Rng As Range
    Dim lRow As Long, lstRow As Long, lsRow As Long
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  14. #14
    Forum Guru contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2010
    Posts
    1,342

    Re: Is this type of copy even possible?

    shg
    I'm really new in VBA and I can make a mistake. So thank you for correction.
    Briefely for the future: I must dim worksheet and range separately? Right.

    I don't want to arque, but the code works, so why to change smth?

    I know I'm wrong here by asking that, but I just want to understand

    thx in advance...
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, «Born in USSR»
    Vusal M Dadashev

    Baku, Azerbaijan

  15. #15
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,770

    Re: Is this type of copy even possible?

    You must specify the data type for each variable, else the variable defaults to a Variant.
    I don't want to arque, but the code works, so why to change smth?
    You don't have to declare variables at all; it's just good practice. It enables VBA to detect type mismatches, and avoids unnecessary errors.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0