Conflicting code?

Fqdd

New Member
Joined
Apr 20, 2011
Messages
3
First of all, I'm kind of a n00b when it comes to VBA, so excuse me if I say anything obvious or even stupid.


Now, I'm trying to build a Workbook for my personal finances. I have written to different functions in VBA to help me do this.

The first one is to calculate what I have in my pocket. It takes the value I have in my pocket(bolso) and withdraws whatever I paid with pocket money from the table range I picked, by looking for the cells which are in italic. Here it is:
Code:
Public Function Bolso(dinheiro As Single)

Application.Volatile True

Dim x As Range
Dim gasto As Single

For Each x In Range("F4:AA34")
    If x.Font.Italic Then
        gasto = gasto + x.Value
    End If
Next x

Bolso = dinheiro - gasto

End Function
The second function I wrote is intended to calculate my monthly balance by taking my income, subtracting what I withdrew and adding what I have in my pocket. Here it is:

Code:
Public Function balance(multibanco As Single)

Application.Volatile True

Dim y As Range
Dim levantado As Single
Dim pocket As Single

For Each y In Range("E4:E34")
    If y.Font.Bold Then
        levantado = levantado - y.Value
    Else
        pocket = pocket + y.Value
    End If
Next y

balance = multibanco - levantado + pocket

End Function
Now, I have those two functions in two different cells, in every monthly sheet (12). The problem is, when I recalculate, it keeps giving me a wrong number, and it adds money in the months I haven't used yet. Aren't those functions correct?



Any help will be much appreciated, sorry if it's a long post and thanks in advance!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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