Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

vb Add 2 cell range values & copy to new workbook

Hello Experts,

I need to take (A1 + A2) value & copy that value to A1 in a different workbook.  How do I do this in VB?

Thanks
0
mike637
Asked:
mike637
1 Solution
 
Rob HensonIT & Database AssistantCommented:
Start VB Recorder:

Put formula in Destination workbook that adds up the two source cells
Copy & Paste Values

Stop Recorder

Look at macro recorded to get basic syntax.

Thanks
Rob H
0
 
sdwalkerCommented:
I don't know if you really want it in a NEW workbook, or an existing one, so here's the code for both.
Sub CopyValueToNewWorkbook()

mySum = Sheets("Sheet1").Range("A1").Value + Sheets("Sheet1").Range("A2").Value
Application.Workbooks.Add

Sheets("Sheet1").Range("A1").Value = mySum

End Sub
 
Sub CopyValueToExistingWorkbook()

myExistingWorkbook = "c:\temp\test.xlsm"

mySum = Sheets("Sheet1").Range("A1").Value + Sheets("Sheet1").Range("A2").Value
Workbooks.Open myExistingWorkbook

Sheets("Sheet1").Range("A1").Value = mySum

End Sub

Open in new window

0
 
mike637Author Commented:
Thank you - I apologize for the delay, but forgot to accept answer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now