Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Add and Subtract ranges (with multiple cells) in vba

I'm trying to subtract one range from another, but instead of looping through
cell by cell, I think it should be possible to perform this opeation in only
a line or two.

Below is the code for what I'm trying to do. Starting_HC, Final_HC and
Turnover are all named ranges with 17R and 11C. Any ideas on what I can
change to make this work?

Sub Headcount()

Range("Final_HC").Value = Range("Starting_HC").Value -
Range("Turnover").Value

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Add and Subtract ranges (with multiple cells) in vba

"Jon5001" wrote in message
...
I'm trying to subtract one range from another, but instead of looping
through
cell by cell, I think it should be possible to perform this opeation in
only
a line or two.

Below is the code for what I'm trying to do. Starting_HC, Final_HC and
Turnover are all named ranges with 17R and 11C. Any ideas on what I can
change to make this work?

Sub Headcount()
Range("Final_HC").Value = Range("Starting_HC").Value -
Range("Turnover").Value
End Sub


Hi Jon,

Here's one way to do it. It takes advantage of the fact that you can
perform basic mathematical operations with the PasteSpecial method.

Sub Headcount()
Range("Final_HC").Value = Range("Starting_HC").Value
Range("Turnover").Value.Copy
Range("Final_HC").Value.PasteSpecial _
Paste:=xlValues, Operation:=xlSubtract
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter value zero into all cells in multiple ranges? Al Excel Discussion (Misc queries) 4 November 26th 09 06:34 AM
Counting Criteria in Cells in Multiple Ranges WalterK Excel Worksheet Functions 4 May 20th 08 03:33 AM
How do you multiple, subtract and divide in the Excel program? Andrea Excel Worksheet Functions 3 July 19th 07 01:44 AM
add and subtract multiple text strings. Tomkat743 Excel Discussion (Misc queries) 1 March 29th 06 01:54 PM
Multiple Criteria (add or subtract) MJSlattery Excel Discussion (Misc queries) 1 June 11th 05 05:38 PM


All times are GMT +1. The time now is 05:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"