Solved

vb Add 2 cell range values & copy to new workbook

Posted on 2011-09-19
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 33

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

752 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