Home | Community | Message Board

Mycohaus
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: Unfolding Nature Unfolding Nature: Being in the Implicate Order   Kraken Kratom Red Vein Kratom   Original Sensible Seeds Autoflowering Cannabis Seeds, Bulk Cannabis Seeds

Jump to first unread post Pages: 1
InvisibleKillerPicklez
Male User Gallery

Folding@home Statistics
Registered: 12/13/07
Posts: 16,920
Loc: Flag
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


Extras: Filter Print Post Top
OfflineMHbound
Ballin Out At All Cost
Male

Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
Re: VBA Help!!! [Re: KillerPicklez]
    #9265836 - 11/18/08 01:00 PM (15 years, 3 months ago)

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.


--------------------


Extras: Filter Print Post Top
OfflineMHbound
Ballin Out At All Cost
Male

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)


--------------------


Extras: Filter Print Post Top
OfflineMHbound
Ballin Out At All Cost
Male

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


--------------------


Extras: Filter Print Post Top
InvisibleKillerPicklez
Male User Gallery

Folding@home Statistics
Registered: 12/13/07
Posts: 16,920
Loc: Flag
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


Extras: Filter Print Post Top
OfflineNubeEnLaMontana
Woodchuck Hunter
Male

Registered: 10/08/08
Posts: 165
Loc: new england
Last seen: 6 months, 16 days
Re: VBA Help!!! [Re: KillerPicklez]
    #9266082 - 11/18/08 01:54 PM (15 years, 3 months ago)

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)


Extras: Filter Print Post Top
OfflineMHbound
Ballin Out At All Cost
Male

Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
Re: VBA Help!!! [Re: NubeEnLaMontana]
    #9266111 - 11/18/08 01:59 PM (15 years, 3 months ago)

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)


Extras: Filter Print Post Top
OfflineNubeEnLaMontana
Woodchuck Hunter
Male

Registered: 10/08/08
Posts: 165
Loc: new england
Last seen: 6 months, 16 days
Re: VBA Help!!! [Re: KillerPicklez]
    #9266164 - 11/18/08 02:11 PM (15 years, 3 months ago)

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


Extras: Filter Print Post Top
OfflineMHbound
Ballin Out At All Cost
Male

Registered: 09/24/07
Posts: 6,512
Loc: Under The Rainbow
Last seen: 6 years, 10 months
Re: VBA Help!!! [Re: NubeEnLaMontana]
    #9266823 - 11/18/08 04:02 PM (15 years, 3 months ago)

Did you ever get it?


--------------------


Extras: Filter Print Post Top
InvisibleKillerPicklez
Male User Gallery

Folding@home Statistics
Registered: 12/13/07
Posts: 16,920
Loc: Flag
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


Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: Unfolding Nature Unfolding Nature: Being in the Implicate Order   Kraken Kratom Red Vein Kratom   Original Sensible Seeds Autoflowering Cannabis Seeds, Bulk Cannabis Seeds


Similar ThreadsPosterViewsRepliesLast post
* Excel/Access VBA gilesypopper 449 7 04/26/09 07:51 AM
by gilesypopper
* getting rid of your tv as a statement Bridgeburner 924 19 10/25/08 11:49 AM
by usefulidiot13
* VOTE: which objective statement should i use? LethalX5 645 10 02/15/07 03:00 PM
by WhiskeyClone
* Is this a strong thesis statement? Rainman420 3,573 5 11/05/08 11:45 PM
by Entropymancer
* Make a profound statement and win a post in this thread!
( 1 2 3 4 5 all )
Asante 7,881 97 11/07/06 06:03 AM
by Fades_to_Black
* a friend posed this question/statement to me
( 1 2 all )
Corporal Kielbasa 2,002 36 08/30/06 02:54 AM
by Papaver
* Official statement to CU students about 4/20 BrainChemistry 1,130 19 04/15/09 08:38 PM
by Ferris
* Jay-z richer than donald trump and other probably untrue statements rawtoxic 4,239 18 11/03/07 06:20 PM
by TODAY

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: Entire Staff
476 topic views. 2 members, 44 guests and 50 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.026 seconds spending 0.007 seconds on 14 queries.