adding / subtracting using VBA code

Mr noob

New Member
Joined
Nov 5, 2011
Messages
49
Hi

I need my code to add together a range of cells from one sheet and place the answer onto another sheet. this is what Ive done so far but am stuck on getting the code to sum the values. any help will be rewarded with a big thanks;)

Sheets("Monthly Report ").Select
Dim rngDate As Range, rngFound As Range
Dim aDate As Date, Shift As String

aDate5 = Sheet1.Cells(2, 2).Value
Shift5 = Sheet1.Cells(4, 2)

Set rngDate5 = Range("d3:bt3")
Set rngFound5 = rngDate5.Find(What:=aDate5)

If Not rngFound5 Is Nothing Then
'True is selection by check box eg true = night shift
If Shift = "True" Then
rngFound5.Offset(52).Select
Selection.Offset(, 1).Select
Else
rngFound5.Offset(52).Select
End If
End If
Selection = Sum("N17+N30+N43+N56+N69+N82+N95+N108+N121+N134+N147+N160+N173")

Sheets("Report").Select
Range("E4").Select
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi

I need my code to add together a range of cells from one sheet and place the answer onto another sheet. this is what Ive done so far but am stuck on getting the code to sum the values. any help will be rewarded with a big thanks;)

Sheets("Monthly Report ").Select
Dim rngDate As Range, rngFound As Range
Dim aDate As Date, Shift As String

aDate5 = Sheet1.Cells(2, 2).Value
Shift5 = Sheet1.Cells(4, 2)

Set rngDate5 = Range("d3:bt3")
Set rngFound5 = rngDate5.Find(What:=aDate5)

If Not rngFound5 Is Nothing Then
'True is selection by check box eg true = night shift
If Shift = "True" Then
rngFound5.Offset(52).Select
Selection.Offset(, 1).Select
Else
rngFound5.Offset(52).Select
End If
End If
Selection = Sum("N17+N30+N43+N56+N69+N82+N95+N108+N121+N134+N147+N160+N173")

Sheets("Report").Select
Range("E4").Select
End Sub
Use Evaluate instead of sum...

Selection = Evaluate("N17+N30+N43+N56+N69+N82+N95+N108+N121+N134+N147+N160+N173")
 
Upvote 0
Hi Rick

For some reason Im getting a #Value! error does the fact that the cells I've selected are sums themselves? or that some values are zeros?
 
Upvote 0
Sorry Rick

My Bad forgot to refer to the sheet that had the correct information,

Code is working perfectly sooo.....

BIG THANK YOU!!!!
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top