LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Copy sum of two columns from one workbook to one column in another

Graham Haughs wrote:

I have a procedure where from a workbook I select and open another
workbook and copy data values from that book (source) to the other
workbook ( target). Part of the procedure is shown below,



With targetfileEntries
.Range("A17:B161").Value = sourcefileEntries.Range("A12:B156").Value
.Range("D17:D161").Value = sourcefileEntries.Range("F12:F156").Value
.Range("E17:E161").Value =
sourcefileEntries.Range("E12:E156").Value
End With

What I would like to do is have a column in the target file i.e
Range("H17:H161").Value and I want it to be have the sum of the values
from the two columns

sourcefileEntries.Range("G12:H156").Value so that in the target file
for eaxmple Cell H17 has the value of the two cells in the source file
G12 plus H12.

I hope this is understandable as I wouls be most grateful for any help
and advice.


A few ways to do this. The simplest is to just add the source data:
With targetfileEntries
For L0 = 17 To 161
.Cells(L0, 8).Value = sourcefileEntries.Cells(L0 - 5, 7).Value + _
sourcefileEntries.Cells(L0 - 5, 8).Value
Next
End With

If the sums need to update with the source data, you could instead do this:
With targetfileEntries
For L0 = 17 To 161
.Cells(L0, 8).Formula = "=SUM([test1.xlsx]Sheet1!$G" & (L0 - 5) & _
":$H" & (L0 - 5) & ")"
Next
End With
....with "[test1.xlsx]Sheet1" replaced with the correct names. (If those
aren't know until runtime, try using sourcefileEntries.Parent.Name and
sourcefileEntries.Name.)

--
I'm on an epic quest to find the 8th day of the week.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy HIDDEN columns to a new workbook Rachel Excel Programming 3 January 17th 10 05:03 PM
I cannot copy the columns of formulas in this Workbook::: AHHHHHHHHHHHHHHHH J Excel Worksheet Functions 6 June 3rd 09 03:13 PM
Copy 3 columns become one column with macro Lyn Excel Programming 6 September 7th 08 12:28 AM
copy two columns without blanks in the first column jeffm Excel Programming 2 May 26th 06 03:49 PM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM


All times are GMT +1. The time now is 05:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"