Solved

vb Add 2 cell range values & copy to new workbook

Posted on 2011-09-19
3
207 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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