+ Reply to Thread
Results 1 to 2 of 2

Append sheets to MASTER sheet retaining chart but with series updated?

  1. #1
    Registered User
    Join Date
    04-27-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    2

    Append sheets to MASTER sheet retaining chart but with series updated?

    Hi

    I have managed to produce VBA to merge my sheets into a MASTER sheet, including a chart from each sheet, successfully BUT....

    The Charts that are copied onto my MASTER sheet retain the series from the original copied from sheets

    How can the VBA be modified to also sync the new charts to the MASTER sheet data?

    For example:-
    Three worksheets - Sample1, SampleXYZ and Master

    Sample1 has a table with x-axis data and y-axis data with several values over rows 19-28
    Above the table is a scatter chart whose series relate to "Sample1" and the x-axis range and the y-axis range - looks good

    Sample1.JPG

    SampleXYZ has a table with x-axis data and y-axis data with several values over rows 19-28
    Above the table is a scatter chart whose series relate to "SampleXYZ" and the x-axis range and the y-axis range - looks good

    SampleXYZ.JPG

    After running my VBA code, on sheet "Master" I have all that is on "Sample1" sheet followed by all that is on "SampleXYZ" sheet - again, looks good

    Master.JPG

    BUT - the charts that are shown on "Master" still relate to Series on "Sample1" and "SampleXYZ". I need the charts on "Master" to relate to the series that they belong to on "Master" (i.e., the first chart should relate to the first copied in table and the second chart should relate to the second copied in table.

    Of course, the second chart and table no longer occupy the same rows that they did in the original "SeriesXYZ" sheet as they have been appended to the previous copy in. The table data now occupies rows 48-57

    So, not only the sheet name needs replacing but also the data range

    Any ideas please? Has to be done with VBA, not manually, as in reality we are talking many worksheets combined into one.

    The code I am using is:-

    Sub MasterSheet()
    Dim ws As Worksheet, LR As Long

    Application.ScreenUpdating = False
    Sheets("Master").Activate

    For Each ws In Worksheets
    If ws.Name <> "Master" Then
    LR = ws.Range("A" & Rows.Count).End(xlUp).Row
    ws.Range("A1:J" & LR).Copy
    ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
    End If
    Next ws
    End Sub

  2. #2
    Registered User
    Join Date
    04-27-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    2

    Re: Append sheets to MASTER sheet retaining chart but with series updated?

    Ok - well, I have solved it myself - but it's not as pretty as I would like, so if there is a better way then please do tell.

    In my particular usage, all of my sheets have a similar format - a scatter chart followed by the data table. In all of my sheets the chart plus data table heading takes up 19 rows so I know that as a fixed element.

    The length of the data table can vary, so that is an unknown element that I need to calculate when appending to the "Master"

    So my new code is thus, and works fine (albeit not elegant):-

    Sub MasterSheet()
    Dim ws As Worksheet, LR As Long, totalLR As Long, strTemp As String
    Dim srs As Series
    Dim idx As Integer

    Application.ScreenUpdating = False
    Sheets("Master").Activate

    For Each ws In Worksheets
    If ws.Name <> "Master" Then
    idx = idx + 1
    FromName = ws.Name
    LR = ws.Range("A" & Rows.Count).End(xlUp).Row
    ws.Range("A1:J" & LR).Copy
    If idx = 1 Then
    ActiveSheet.Paste Range("A65536").End(xlUp).Offset(0, 0)
    Else
    ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
    End If
    ''' discover series range
    ''' There will be multiple Columns, all with same ranges.....
    ''' Original from and to range:-
    ofrRng = "$" & (LR - (LR - 19) + 1) & ":"
    otoRng = "$" & LR

    ''' New from and to range:-
    If idx = 1 Then
    nfrRng = ofrRng
    ntoRng = otoRng
    Else
    nfrRng = "$" & (totalLR + 20) & ":"
    ntoRng = "$" & (totalLR + LR)
    End If

    totalLR = totalLR + LR

    ActiveSheet.ChartObjects(idx).Activate
    For Each srs In ActiveChart.SeriesCollection
    strTemp = WorksheetFunction.Substitute(srs.Formula, FromName, "Master")
    strTemp = WorksheetFunction.Substitute(strTemp, ofrRng, nfrRng)
    strTemp = WorksheetFunction.Substitute(strTemp, otoRng, ntoRng)
    srs.Formula = strTemp
    Next
    End If
    Next ws
    End Sub

+ 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. Wen Master Excel Sheet Updated, Linked Sub Sheets Auto Update
    By juxtapozthis in forum Excel General
    Replies: 0
    Last Post: 02-17-2015, 05:32 PM
  2. [SOLVED] master sheet updated itself with new added sheets
    By greatairi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-22-2013, 02:50 AM
  3. master sheet updated itself with new added sheets
    By greatairi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-21-2013, 03:04 AM
  4. I would like to append and update excel master workbook with new and updated rows.
    By uvwaves in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2013, 03:14 PM
  5. Master sheet continually updated?
    By dlab85 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2012, 01:04 PM
  6. find for a value and append the value in master sheet
    By Sindhuja in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2012, 01:47 AM
  7. how do i append 4 differnt worksheets in a new master work sheets
    By darsg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2005, 05:06 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