Macro's owrite eachother

brent1991

New Member
Joined
Sep 15, 2014
Messages
13
Hello,

I'm pretty busy with an advanced excel sheet but I'm stuck with at the moment with one of my last VBA codes.

I'm using the following code:



Sub MG15Sep58()
Dim Budget As Double
Dim rTime As Long
Dim sMth As Long
Dim n As Long
Dim c As Long
Dim Lst As Integer
Dim st As Long
Lst = Range("C" & Rows.Count).End(xlUp).Row
If Lst >= 19 Then Range("C19").Resize(Lst - 18, 2).ClearContents
Budget = Range("C9"): rTime = Range("C10"): sMth = Range("C11")
c = 19
st = sMth - 1
For n = c To c + rTime - 1
Cells(n + st, 2) = MonthName(sMth)
Cells(n + st, 3) = Budget / rTime
sMth = sMth + 1
If sMth = 13 Then sMth = 1
Next n


End Sub

and in the next macro i'm using almost the same code but with a different input:

Sub MG15Sep59()
Dim Budget As Double
Dim rTime As Long
Dim sMth As Long
Dim n As Long
Dim c As Long
Dim Lst As Integer
Dim st As Long
Lst = Range("C" & Rows.Count).End(xlUp).Row
If Lst >= 19 Then Range("C19").Resize(Lst - 18, 2).ClearContents
Budget = Range("C15"): rTime = Range("C16"): sMth = Range("C17")
c = 19
st = sMth - 1
For n = c To c + rTime - 1
Cells(n + st, 2) = MonthName(sMth)
Cells(n + st, 3) = BudgetE / rTime
sMth = sMth + 1
If sMth = 13 Then sMth = 1
Next n


End Sub

When I try to get the results it is overwriting each other. The perfect situation is that he adds it to to other results

example:

if there is 0 and you need to add 20 the end result is 20
if there is 20 and you need to add 20 the end result is 40.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Upvote 0
You haven't changed:

Rich (BB code):
Cells(n + st, 3) = Budget / rTime

to this:

Rich (BB code):
Cells(n + st, 3).Value = Cells(n + st, 3).Value + (Budget / rTime)
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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