View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Adding Rabges without for each loops

One mo

Option Explicit
Sub AddRanges()
Dim r1 As Range
Dim r2 As Range
Dim r3 As Range

Set r1 = Range("a1:a5")
Set r2 = Range("b1:b5")
Set r3 = Range("c1:c5")

r3.Value = r1.Value
r2.Copy
r3.PasteSpecial Paste:=xlPasteValues, _
operation:=xlPasteSpecialOperationAdd

Application.CutCopyMode = False

End Sub

It's the same as doing
select r1
edit|copy
select r3
edit|Paste special values (r1 to r3)

then
select r2
edit|copy
select r3
edit|Paste special|paste values|checking add



"mdalamers via OfficeKB.com" wrote:

Hi,

I should like to add the cells in two ranges WITHOUT having to loop through
each range separately.
Suppose the cells A1 to A5 in my worksheet are filled, as well as cells B1 to
B5

Now I thought this would do the trick. But apparently not:
Sub AddRanges()
Dim r1 As Range
Dim r2 As Range
Dim r3 As Range

Set r1 = Range("a1:a5")
Set r2 = Range("b1:b5")
Set r3 = Range("c1:c5")

r3.value = r1.value + r2.value
End Sub

Any suggestions?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200703/1


--

Dave Peterson