You have a "Do" statement but no concluding Loop. Either conclude the loop or remove the Do.
I am relatively new to coding in VBA and keep getting the compile error and cannot figure out why it keeps coming up. Any help on quelling the pop up would be helpful.
Here is the code where I keep getting the error:
VB:Sub tax() Tester = 0 livePriceTotal = Cells(lastLiveRow + 1, 2) liveTaxTotal = Cells(lastLiveRow + 1, 3) silentPriceTotal = Cells(lastSilentRow + 1, 7) silentTaxTotal = Cells(lastSilentRow + 1, 8) taxRate = Range("G1").Value taxExempt = Range("G2") taxRateAdj = ((liveTaxTotal + silentTaxTotal) * (100)) / (livePriceTotal + silentPriceTotal - taxExempt) Do If liveTaxTotal + silentTaxTotal = (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 1 'Cells(1, 8) = taxRateAdj If liveTaxTotal + silentTaxTotal <= (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 2 'ActiveCell(1, 8) = taxRateAdj If liveTaxTotal + silentTaxTotal > (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 3 If Tester = 1 Then taxRate If Tester = 2 Then taxRate If Tester = 3 Then taxRateAdj End Sub
You have a "Do" statement but no concluding Loop. Either conclude the loop or remove the Do.
Removed the "Do" statement.
Still getting the same error this time the highlighted term is "taxRate"
Did I not declare taxRate correctly?
Hello vtflee,
Welcome to Ozgrid.
You should never code without using Option Explicit. It forces you to properly declare your variables.
Turn on Option Explicit while in the VB Editor: Menu > Tools > Options > check the box for Require Variable Declaration
Unless you haven't posted all of your code, none of your variable are declared.
I don't see where you have defined "lastliverow" or "lastSilentrow".
Correct your variable delcarations, then your loop structure, then step through the code.
Correct/Efficient Uses of Excel Loops
AAE
----------------------------------------------------
Forum Rules | Message to Cross Posters | How to use Tags
Thanks.
I did declare it in the beginning but did not include it in my previous code. I added it right after the sub tax and ran it again, but still getting the same error and it stops at taxRate again.
Here's the code again:
VB:Sub tax() Dim livePriceTotal As Currency Dim liveTaxTotal As Currency Dim silentPriceTotal As Currency Dim silentTaxTotal As Currency Dim taxRate As Long Dim taxCorrect As Long Dim taxExempt As Currency Dim taxRateAdj As Long Tester = 0 livePriceTotal = Cells(lastLiveRow + 1, 2) liveTaxTotal = Cells(lastLiveRow + 1, 3) silentPriceTotal = Cells(lastSilentRow + 1, 7) silentTaxTotal = Cells(lastSilentRow + 1, 8) taxRate = Range("G1").Value taxExempt = Range("G2") taxRateAdj = ((liveTaxTotal + silentTaxTotal) * (100)) / (livePriceTotal + silentPriceTotal - taxExempt) If liveTaxTotal + silentTaxTotal = (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 1 'Cells(1, 8) = taxRateAdj If liveTaxTotal + silentTaxTotal <= (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 2 'ActiveCell(1, 8) = taxRateAdj If liveTaxTotal + silentTaxTotal > (livePriceTotal + silentPriceTotal - taxExempt) * taxRate Then Tester = 3 If Tester = 1 Then taxRate If Tester = 2 Then taxRate If Tester = 3 Then taxRateAdj End Sub
Where do you define lastLiveRow? What is in G1?
G1 is a tax rate. That value is being pulled from another spreadsheet. I used a vlookup function in the G1 cell.
Post a workbook.
The other workbook where the tax rates are being pulled is too big to post. Hope that's not an issue.
Hard to tell but if you declare something as Long it covers integers so if you have something 0.08 you need to declare as Double. Somewhat mystified by the error message you were getting though. I get an overflow error on the taxrateadj line.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks