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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
thanks fr your quick reply.

What's being overwritten? And what is BudgetE in your second procedure?

The output of the first marco is being overwritten when i start my second macro (because it has to be in the same colums)

BudgetE is extra budget (so addditional budget)
 
Upvote 0
I asked about BudgetE because you haven't declared it or assigned it a value anywhere. Maybe you want:

Code:
Cells(n + st, 3).Value = Cells(n + st, 3).Value + (BudgetE / rTime)

because that's a ratio and you don't know the original constituents.
 
Upvote 0
I asked about BudgetE because you haven't declared it or assigned it a value anywhere. Maybe you want:

Code:
Cells(n + st, 3).Value = Cells(n + st, 3).Value + (BudgetE / rTime)

because that's a ratio and you don't know the original constituents.

Hi sorry. That's a mistake that needs to be Budget.
 
Upvote 0
Hello,

Unfortunately not. This was a bug what I already solved the other day, But pasted the wrong code in this forum. I changed the E but the output is still the same

When i calculate my first macro the result is divided in C19 untill C42. For example two times 200 in cell C20 en C21.

When i use the second macro and the outcome is 200 in cell C30 en C31 it will automattically erase the first result. in C20 en C21.
 
Upvote 0
How can it be overwriting? It's adding to what's already there:

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

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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