Data from one Workbook automatically go into another


Posted by Matteo on June 22, 2001 8:50 AM

What is the macro ? to put data from a particular cell into another cell in a different workbook, different sheets. Also is there a way to bring over just the values of that cell if it's a formula ? e.g. cell c4 = +c2+c3 (in the orig workbook).

The numbers are all in place in the original workbook, so once I put the address in the new cell/sheet/workbook, do the numbers automatically appear or is there a command I have to excercise ?

Thanks...



Posted by Damon Ostrander on June 22, 2001 9:01 AM

Matteo,

To do this, both workbooks must be open in Excel.
Whenever you refer to cell ranges, there is a qualifier that preceeds the range reference similar to a file path that describes where the cell is located. Normally we don't provide the entire qualifier because if we leave it off Excel assumes it is the active workbook and the active sheet, but it doesn't have to be. So, to refer to cells in another workbook in VBA, just use the complete qualifier, e.g., to put the value of cell D5 of the active worksheet in the active workbook into cell B3 of worksheet "Cost Data" of workbook NewWorkbook.xls:

Workbooks("NewWorkbook").Worksheets("Cost Data").[B3].Value = [D5].Value

You would have to run a macro containing this statement every time you want the contents to be transferred.

Happy computing.

Damon