Solved

vb Add 2 cell range values & copy to new workbook

Posted on 2011-09-19
3
197 Views
Last Modified: 2012-05-12
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
Comment
Question by:mike637
3 Comments
 
LVL 32

Expert Comment

by:Rob Henson
ID: 36561067
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
 
LVL 12

Accepted Solution

by:
sdwalker earned 500 total points
ID: 36561250
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
 

Author Closing Comment

by:mike637
ID: 37124274
Thank you - I apologize for the delay, but forgot to accept answer.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now