Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
I have created a few UserForms and one of them is for the User to input
various amounts as required. I'm having some difficulty in understanding how the dim statement works in determining what the input type that can be entered, etc. Some things I can't get right a I want to restrict the input to numbers only. I want the TextBoxes to be blank and not show a "0" OR have it so that the 0 amount is highlighted so that when the user clicks in the box it overwrites the 0. (When I use "" instead of 0 when resetting the Textboxes to blank I get a type missmatch alert.) Below is my "creation" which may be a bit rough but it works other than the problems above. Thanks for azny help! Rob Private Sub OK_Click() Dim L As Integer Dim G As Integer Dim C As Integer L = LoanTextBox.Value 'Loan amount G = GiftTextBox.Value 'Gift amount C = LoanGiftTextBox.Value 'Converted (Loan to a Gift) amount If L = 0 And G = 0 And C = 0 Then MsgBox "You must enter an amount!" Exit Sub End If If C < 0 And L < 0 Then GoTo Message1 If C < 0 And G < 0 Then Message1: MsgBox "You cannot convert a loan and also enter any amounts for Loan or Gift at the same time!" LoanTextBox.Value = 0 GiftTextBox.Value = 0 LoanGiftTextBox.Value = 0 Exit Sub End If If L < 0 Then ActiveCell.Offset(0, 1).Value = L End If If G < 0 Then ActiveCell.Offset(0, 2).Value = G End If If C ufLoanGift.TextBox1.Text Then Unload Me MsgBox "The amount you have entered for convertion to Gift is more than the total of the Loans for this person." ufLoanGift.TextBox1.Text = ActiveCell.Offset(0, 6).Value ufLoanGift.Show Else If C < 0 Then ActiveCell.Offset(0, 1).Value = -C ActiveCell.Offset(0, 2).Value = C ActiveCell.Offset(0, 4).Value = Comment End If Range("C221").End(xlUp)(1, 3).Select ActiveCell.Offset(0, 4).ClearContents ActiveCell.Offset(0, 1).Select With Sheet1 .PivotTables("PivotTable1").RefreshTable End With Unload Me ufDate.Show End If End Sub Private Sub LoanTextBox_Change() If C < 0 Then MsgBox "You cannot enter an amount in this box if there is an amounts in the Convert Loan to Gift box!" C = 0 End If End Sub Private Sub GiftTextBox_Change() If C < 0 Then MsgBox "You cannot enter an amount in this box if there is an amounts in the Convert Loan to Gift box!" C = 0 End If End Sub Private Sub LoanGiftTextBox_Change() If L < 0 Then GoTo Message If G < 0 Then Message: MsgBox "You cannot enter an amount in this box if there are amounts in the Loan or Gift boxes!" L = 0 G = 0 End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
UserForm Data to Spreadsheet | Excel Discussion (Misc queries) | |||
Auto calculation on a userform | Excel Discussion (Misc queries) | |||
Data Validation Cell - Move to UserForm | Excel Worksheet Functions | |||
Cell Content from UserForm Not Retained | Excel Discussion (Misc queries) | |||
How can I run a macro in the background whilst a UserForm is visib | Excel Discussion (Misc queries) |