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:
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:
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!
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
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
Any help will be much appreciated, sorry if it's a long post and thanks in advance!