using VBA to times and add a range and paste to one cell

nzkiwi

New Member
Joined
Nov 27, 2012
Messages
24
Ok so i have been self teaching myself and so far i have written the code below, which is returning the individual values i want and putting them in the range "FirstTargetCell".

what i really want to do now is put one figure on the summary sheet in "C30" that sums all the figures or the FirstTargetCell, thats easy but i want to do it another way.

i dont want to use FirstTargetCell but rather within the code i have written, say i create "C" and C=0 to start with, at the end of the 1st loop of IF statements in the code i want "C" to equal the result that would have been placed in the first cell, then after the second loop of IF statements C=C+ (the next result)

Which at the end of all the loops C= Total days labour for heat and i want this value in "C30"Ok so i have been self teaching myself and so far i have written the code below, which is returning the individual values i want and putting them in the range "FirstTargetCell".

what i really want to do now is put one figure on the summary sheet in "C30" that sums all the figures or the FirstTargetCell, thats easy but i want to do it another way.

i dont want to use FirstTargetCell but rather within the code i have written, say i create "C" and C=0 to start with, at the end of the 1st loop of IF statements in the code i want "C" to equal the result that would have been placed in the first cell, then after the second loop of IF statements C=C+ (the next result)

Which at the end of all the loops C= Total days labour for heat and i want this value in "C30"


Code:
Sub summary()


Dim FirstCell As Range
Dim FirstTargetCell As Range
Dim I As Integer
Dim TMR As Single


Set Myrange = Sheets("Team List").Range("C1:d500")

Set FirstCell = Sheets("heat").Range("A5")
Set FirstTargetCell = Sheets("Summary").Range("M6")
I = 0



TMR = Application.WorksheetFunction.VLookup(FirstCell, Myrange, 2, False)

Do

If FirstCell.Offset(I, 7).Value = "" Then
FirstTargetCell.Offset(I, 0).Value = ""
Else

If FirstCell.Offset(I, 3).Value = "AL" Then

FirstTargetCell.Offset(I, 0).Formula = TMR * 0 * FirstCell.Offset(I, 7)
Else


If FirstCell.Offset(I, 3).Value = "LS" Then
FirstTargetCell.Offset(I, 0).Formula = TMR * 0 * FirstCell.Offset(I, 7)

Else


If FirstCell.Offset(I, 3).Value = "SW" Then
FirstTargetCell.Offset(I, 0).Formula = TMR * 1.5 * FirstCell.Offset(I, 7)
Else


If FirstCell.Offset(I, 3).Value = "NL" Then
FirstTargetCell.Offset(I, 0).Formula = TMR * 1.5 * FirstCell.Offset(I, 7)
Else

FirstTargetCell.Offset(I, 0).Formula = TMR * FirstCell.Offset(I, 7)

End If
End If
End If
End If
End If
I = I + 1


Loop Until FirstCell.Offset(I, 0).Value = ""

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,776
Messages
6,126,830
Members
449,343
Latest member
DEWS2031

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