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
mike637Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sdwalkerConnect With a Mentor Commented:
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
 
Rob HensonFinance AnalystCommented:
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
 
mike637Author Commented:
Thank you - I apologize for the delay, but forgot to accept answer.
0
All Courses

From novice to tech pro — start learning today.