+ Reply to Thread
Results 1 to 2 of 2

Macro to copy spreadsheet and graph on new workbook values only

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Macro to copy spreadsheet and graph on new workbook values only

    Hi everyone,

    I would like to do what I think would be a simple thing for you VBA geniuses but very difficult for me to say the least.

    I have attached a very basic example to capture what I'm trying to achieve. I have a massive workbook on which I track inventory via figures and graphs (on separate spreadsheets). My aim is to have a macro (that I'd link to a shape) to copy the highlighted sections in yellow as well as the graph from the other spreadsheet on a new workbook. The layout needs to be slightly different as it will be sent to different users who shouldn't have access to all the info available in the original workbook.

    I would like all the values to be copied as "values only" and the graph as a bitmap. Also, there will probably be conditional formatting in columns B, C, D, G and H mainly dependent on how small or high the figures are. In a perfect world, I would also like to copy this formatting across.

    The end result (which would need to be on a different workbook) is on the spreadsheet called "Target Layout", including the frozen pans and background colors.

    I've managed to do something very dodgy with the macro recorder so I would assume it could work but I definitely some help.

    Anyone's help on this would be massively appreciated :-D

    Sub

    Example inventory.xlsx

  2. #2
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Re: Macro to copy spreadsheet and graph on new workbook values only

    Hi everyone,

    I managed to get a few things done but now I have a subscript range error:

    Sub Test()
    '
    ' Test Macro
    '
        Set NewBook = Workbooks.Add
        Do
        fName = Application.GetSaveAsFilename
        Loop Until fName <> False
        NewBook.SaveAs Filename:=fName
    
        Cells.Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.349986266670736
            .PatternTintAndShade = 0
        End With
        Windows("Example Inventory Macro.xlsm").Activate
        Range("B1:D19,G1:H19").Select
        Range("G1").Activate
        Selection.Copy
        Windows("Book1").Activate
        Range("B17").Select
        ActiveSheet.Paste
        Range("B19:F35").Select
        Application.CutCopyMode = False
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Columns("B:F").Select
        Range("B13").Activate
        Columns("B:F").EntireColumn.AutoFit
        Rows("16:16").Select
        ActiveWindow.FreezePanes = True
        Windows("Example Inventory Macro.xlsm").Activate
        Sheets("Graph").Select
        ActiveSheet.ChartObjects("Chart 1").Activate
        Application.CutCopyMode = False
        ActiveChart.ChartArea.Copy
        Windows("Book3").Activate
        ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:= _
            False
    End Sub
    I assume it is because Windows("Book1").Activate does not refer to the actual file I have just saved but I don't know how to make it capture the file name I just entered.

    The rest of the code seems to be reasonably ok (still working through a few things) if I have a file with the appropriate name but I need to find a work around.

    Any guess from anyone?

    Thanks,

    S

+ 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. Replies: 0
    Last Post: 07-23-2013, 05:45 PM
  2. Replies: 9
    Last Post: 06-24-2013, 04:14 PM
  3. Copy graph to new workbook while leaving data in original workbook
    By smjpl in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 12-10-2012, 12:49 PM
  4. Macro to copy a sheet as values into a new workbook
    By yjbrody in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2009, 02:32 PM
  5. [SOLVED] copy spreadsheet in new workbook, macro problem
    By matthias in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2006, 02:50 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