views:

1011

answers:

5

I have written a script which creates a complex Excel sheet which contains data from several data sources. The data on each sheet is usually 1-5 rows. It would be great if I could create another sheet which would display the data from the other sheets online (i.e. the overview sheet should change as I change the data sheets). I also need to format the data with various styles and have the overview sheet copy them. Lastly, the data sheets have different column widths.

I was thinking that I could simply import the sheets. This works when I save each sheet into a single file and then import them as OLE objects. Isn't there a way to achieve the same effect with just a single file?

[EDIT] What I need is to tell Excel "draw A1:F3 on Sheet2 on Sheet1 into cell A1".

"Insert Object" offers me to create a Word document or a PP presentation and put that into a cell, but I can't create a new Excel sheet and put that into a cell. What gives?

A: 

A single Excel workbook can contain multiple sheets. Formulas in one sheet can reference cells in another sheet in the same workbook.

JonnyBoats
That doesn't solve the layout problems. There is no way to says "copy the layout+data from cell sheet;column;row". Plus it doesn't allow to five the column "B" two different widths, depending on the row.
Aaron Digulla
+2  A: 

Hey,

if you want a build a Solution by yourself try:
http://poi.apache.org/
Apache POI - Java API To Access Microsoft Format Files Its really easy to use...and you can easily format data etc...

I used POI with Apache Digester (http://commons.apache.org/digester/)
to read Data from XML Files and create Excel Sheets.

[EDIT] With this approach, you can read in the existing Excel sheet, copy the relevant cells between worksheets (including the formatting). That doesn't solve the "different column widths" and the "online update", though.

bastianneu
As I said, I already solved that. What I need is to tell Excel "draw A1:F3 on Sheet2 on Sheet1 into cell A1".
Aaron Digulla
Well...if u already solved the problem of placing data in one Sheet2..why is it not possible to place that Data in Sheet1?I think i am not getting the point...sry
bastianneu
I think bastianneu meant that with POI you can read data/style/formatting from sheet1 and place it in the sheet2.
01
you are right Boat Monkey
bastianneu
+1 for that. I took the liberty to edit the answer. Feel free to enhance it some more.
Aaron Digulla
Different Columnwidth...hmm let me see i solved it via:http://poi.apache.org/spreadsheet/quick-guide.html#Autofitor if you want to edit columnwidth on your on try:sheet.setColumnWidth(cell or column, 256*20);FYI: 256*20 = 20 Characters Wide--what do mean with using online update? Hyperlinks?Maybe this will help you:http://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks
bastianneu
A: 

You can reference other sheets with the following syntax:

SheetName!Cell

so in Sheet1, A1 a formula of

=Sheet2!B4

will have a live reference to the value in sheet2 at B4

Scott Weinstein
How do I reference the formatting of Sheet2!B4?
Aaron Digulla
You can use the PasteSpecial method to 'paint' the formatting from the source data to the new summary
Lunatik
The format brush is another usefull tool here. Formats are not brought over for good reason. It's a way to separate the "model" from the "view"
Scott Weinstein
So in a nutshell, Excel is designed not to do what I want? Well, I could create a Word document, put an Excel sheet in there and then paste this monstrosity into a cell ...
Aaron Digulla
I think the best you could do is use a macro to copy the formats Range("A1:Z30").Select Selection.Copy Range("Sheet1!A1").Select Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False
Scott Weinstein
+2  A: 

Copy the range. Move to the cell you want to hold the reference. Hold the Shift key down as you select the Edit menu. Notice there are new menu items; "Paste Picture" and "Paste Picture Link". You want to select "Paste Picture Link". Now whenever the "source" is updated or the format changes, the "destination" will update.

Sub DemoIt()

    'open excel and vbe windows side-by-side
    '   to see results when break points hit

    'setup values
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "A"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "B"
    Range("A3").Select
    ActiveCell.FormulaR1C1 = "C"

    'select "source" values and copy
    Range("A1:A3").Select
    Selection.Copy

    'move to "destination"
    Range("B1").Select

    'paste the "picture link"
    ActiveSheet.Pictures.Paste(Link:=True).Select
    Application.CutCopyMode = False

    'check out results
    Stop

    'change values
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "99"

    'notice "destination" changed
    Stop

    'change formatting
    Range("A3").Select
    Selection.Font.Size = 20

    'notice formatting changed
    Stop

End Sub
AMissico
+1  A: 

You can use camera objects.

  1. Copy the range you want on the cover sheet
  2. Go to the cover sheet
  3. Hold down shift and click the Edit menu
  4. Click the Paste Picture Link menu item

This pastes a dynamic picture object that updates whenever the corresponding region on the data sheet changes.

Ant