|
KillerPicklez



Registered: 12/13/07
Posts: 16,920
Loc:
|
VBA Help!!!
#9265824 - 11/18/08 12:58 PM (15 years, 3 months ago) |
|
|
Alright I am just doing the basics for VBA and I am writing this code for it to do calculate taxes
Anyways. I need to have the resultant variable which I have labeled as "sngTaxOwed" to come be displayed in cell C4
Here is my code. again the bolded line is where I am having the trouble, right now
Private Sub cmdIF_Click() Dim sngIncome As Single Dim sngTaxOwed As Single
sngIncome = Range("C3").Value 'sngIncome is the income of the client wishing to find the amount of tax owed sngTaxOwed = ("C4").Value
'Below this line is where I am working on the If-Then statements for sngTaxOwed If sngIncome <= 7300 Then sngTaxOwed = sngIncome - (sngIncome * 0.1) End If
If sngIncome > 7300 And sngIncome <= 29700 Then sngIncome = sngIncome - (sngIncome * 0.15) End If
If sngIncome > 29700 And sngIncome <= 71950 Then sngIncome = sngIncome - (sngIncome * 0.25) End If
If sngIncome > 71950 And sngIncome <= 150150 Then sngIncome = sngIncome - (sngIncome * 0.28) End If
If sngIncome > 150150 And sngIncome <= 326450 Then sngIncome = sngIncome - (sngIncome * 0.33) End If
If sngIncome > 326450 Then sngIncome = sngIncome - (sngIncome * 0.35) End If
End Sub
THANK YOU!!! This problem is driving me nuts! And it should be fairly simple
|
MHbound
Ballin Out At All Cost


Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
|
|
I know VB, c/c++, but should the cell be in quotation??? I wouldn't think it should be, but like I said I don't know anything about this language.
--------------------
|
MHbound
Ballin Out At All Cost


Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
|
Re: VBA Help!!! [Re: MHbound]
#9265838 - 11/18/08 01:01 PM (15 years, 3 months ago) |
|
|
Maybe like (C4.value)
--------------------
|
MHbound
Ballin Out At All Cost


Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
|
Re: VBA Help!!! [Re: MHbound]
#9265886 - 11/18/08 01:12 PM (15 years, 3 months ago) |
|
|
Wish I could delete the first posts...They are wrong, and I think I know what's wrong.
Try using a IF ELSE statement. For example:
http://www.techonthenet.com/excel/formulas/if_then.php
--------------------
|
KillerPicklez



Registered: 12/13/07
Posts: 16,920
Loc:
|
Re: VBA Help!!! [Re: MHbound]
#9265942 - 11/18/08 01:24 PM (15 years, 3 months ago) |
|
|
Nah your first 2 posts were much closer to what I need than the last one.
Im fairly confident that my If-then code is correct. I just need to make it so that running the code results in the answer being displayed in cell C4
It should be a very basic, simple code. I dont know why I cant think of it and why it is giving me such fits
|
NubeEnLaMontana
Woodchuck Hunter


Registered: 10/08/08
Posts: 165
Loc: new england
Last seen: 6 months, 16 days
|
|
unless I'm totally misreading you, you need to switch the order.
"sngTaxOwed = ("C4").Value" should be "("C4").Value = sngTaxOwed"
You're trying to put the value of sngTaxOwed in C4, right?
edit: also, does that need to be 'Range("C4").Value'? I always use 'Worksheets("worksheetname").Range("cellname").value' but maybe I'm just doing it the long way.
Edited by NubeEnLaMontana (11/18/08 01:58 PM)
|
MHbound
Ballin Out At All Cost


Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
|
|
You may need to run sngTaxOwed through the val function first before it can be assigned to that variable.
:::::::::
Dim sngIncome As Single Dim sngTaxOwed As Single Dim x As Single
sngIncome = Range("c3").Value 'sngIncome is the income of the client wishing to find the amount of tax owed x = Val(Range("c4").Value) sngTaxOwed = x
Try something like that.
--------------------
Edited by MHbound (11/18/08 02:14 PM)
|
NubeEnLaMontana
Woodchuck Hunter


Registered: 10/08/08
Posts: 165
Loc: new england
Last seen: 6 months, 16 days
|
|
and shouldn't that line be below all the if/then logic just prior to 'end sub'? Otherwise sngTaxOwed will be null when you're trying to write it to C4
|
MHbound
Ballin Out At All Cost


Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
|
|
Did you ever get it?
--------------------
|
KillerPicklez



Registered: 12/13/07
Posts: 16,920
Loc:
|
Re: VBA Help!!! [Re: MHbound]
#9267994 - 11/18/08 06:36 PM (15 years, 3 months ago) |
|
|
oh well Im not sure what I did wrong. I turned in the assignment and it looked as though I could have had any number of errors. I will get it straightended out after I smoke some weed and all will be good
|
|