Posting to Ledger (Inputbox bug)

jcvoth

Board Regular
Joined
Feb 23, 2004
Messages
198
Dear all,

I am creating a ledger spreadsheet that posts journal entries. The format is the following:
Click the command button and an inputbox opens asking which of the three possible transaction types the user wants to do. In the code, I created a switch that allows me to choose OE, PMT, or CLS. If the user chooses an alternate type, a msgbox opens and tells the user of their failure and it stops the function. If the user chooses a correct type, they are prompted to give a dollar amount.

Here is where it gets tricky. If the user suddenly changes his/her mind and hits cancel, the function is not cancelled. In fact, the entry is posted, except at $0. Is there a way I can have the function halt if the cancel is chosen? For some reason, it worked in the first switch, but not the second.

Following is the code I have so far. (Go easy on me, I am a VBA newbie.)

Sub FunTran()
Application.ScreenUpdating = False
usermsg = InputBox("What Type of Transaction do you wish to enter? (OE: Addition or Withdrawl from the Business, PMT: A Payment to the principle lender; MBNA, or CLS: A Journal entry to close the Accounting Period.)")
Select Case usermsg
Case vcancel
Sheets("Financials").Range("a1").Select
Exit Sub

Case "PMT"
Sheets("Journal").Range("r22") = InputBox("How much do you wish to pay MBNA?")
Sheets("Journal").Range("k23:r24").Copy
Sheets("Journal").Select
Range("a3").End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial Paste:=xlValues
Sheets("Journal").Range("r22").Select
ActiveCell.ClearContents
Sheets("Financials").Select
Range("a1").Select

Case "OE"
Sheets("Journal").Select
Range("r25") = InputBox("How much to you wish to add or subtract from the business?")
Range("k26:r27").Copy
Range("a3").End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial Paste:=xlValues
Range("r25").ClearContents
Sheets("Financials").Select
Range("a1").Select

Case "CLS"
Sheets("Journal").Select
Range("k18:r21").Copy
Range("a3").End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial Paste:=xlValues
Sheets("Financials").Select
Range("a1").Select
Case Else
MsgBox ("Available Transactions are OE: Addition or Withdrawl from the Business, PMT: A Payment to the principle lender; MBNA, or CLS: A Journal entry to close the Accounting Period.")
Exit Sub
End Select
End Sub

Thank you in advance for your wonderful help. I have been an avid reader of this board for several days, but this is my first post.

-Jarrod
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi Jarrod, its not seeing the cancel. Theres actually a constant vbCancel not vcancel but Excel returns different things depending upon the method you use. Look up Input Box in the VBE (or highlight the word InputBox in your code and press F1) and look at the remarks. Input returns a zero length string if cancel is pressed (or nothing is entered and they click OK) so you need to test for that,

Replace
Code:
Case vcancel 
Sheets("Financials").Range("a1").Select 
Exit Sub

With
Code:
Case vbNullString 'you could also use Case ""
Sheets("Financials").Range("a1").Select 
Exit Sub

hth

PS: If you want the user just to have three choices you could build your own Userform and have a combobox with just the three options if you wanted. :biggrin:
 

jcvoth

Board Regular
Joined
Feb 23, 2004
Messages
198
Thank you so much for your help!

I think you're right with the userform idea. Otherwise I will need to create a switch in each of the individual cases of the original switch.

I think I will take your advice and learn how to create a userform.

-Jarrod
 

Watch MrExcel Video

Forum statistics

Threads
1,123,385
Messages
5,601,331
Members
414,446
Latest member
CRAVIN

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
Top