Validating a text box of a User Form - excel

I have two sheets named "In-house inventory" and "Maintenance Details". I am using a User Form to feed data into the Maintenance Details datasheet. There is a combo box to select the material type used for the maintenance and a text box to enter the quantity of the material used. I want to generate an error message if the material quantity entered by the user is greater than the available quantity of the material in the inventory. (For example, inventory has 15L of Lubricant oil, if the user selects Lubricant oil from the combo box and enter the quantity as 20L, I want to generate an error message saying that the Entered material quantity is greater than the available quantity in the inventory.)
This is what I did and this generates an error message for every value entered to the quantity text box.
I am very new to VBA and any help would be highly appreciated.
Thanks a lot in advance.
Private Sub MaterialQuantityTextBox_AfterUpdate()
If MaterialQuantityTextBox.Value > Application.WorksheetFunction.VLookup(Me.InhouseMaterialComboBox, Sheet6.Range("B:D"), 3, False) Then
MsgBox " Quantity is greater than the quantity available in the Inventory. Enter a valid quantity"
End If
End Sub

Related

How to create stock price alert with EXCEL/How to handle Auto refreshing data ,Dynamic data with macros

My aim with this is to create stock price alert(like Pop up message)/Because excel sheet contains more than 300 stock list
i don't want to scroll down excel sheet every time to check if refreshed price falls into any of these categories..
I have 8 columns in excel which consists of following information-
Column A-Stock Name
Column B-current stock price data which refreshes in every 5-10 seconds...
Column C-Ticker name
Next columns(D,E,F,G,H) i set them with manually entered prices for corresponding stocks for alert purpose.
If Refreshed price in column B falls in range 99% or 101% of columns values in D,E,F,G or H
i want to display a pop up message with Stock name with that cell address of corresponding cell in column D,E,F,G,or H ...
For Ex. If D2,E2,F2,G2 or H2 contains value 104.50 which is static and if B2 cell update its price dynamically to 105 then, B2 value falls in range 99% of D2(103.95) and 101% of D2(106.05) of D2..Once this Condition satisfies i want a popup alert...Any kind of help to simplify this task is most appreciated...
Check please the latest update of file:
https://drive.google.com/file/d/1itIZl3kMFR9f2Tf3ObB0qUprfp2rLm4r/view?usp=sharing
I added a scheduler, another sub iterates for each cell in B column every 5 seconds
I changed msgbox into debug.print to prevent crash excel.
You can find output messages in Immediate window:
Added:
Blockquote

Input box prompting for second data entry to store data, can we make it store on the first entry?

I am trying to put an activex textbox over a cell (B23), which is hiding the text cell with the secure data. The textbox has the passwordchar set to *. When I put the input box function in the textbox it pops up when they start to type, then when I push okay the box clears and asks me to reenter my data then it saves to B23. Is there a way to make this work on the first time, or if on the second popup have it say "please verify your entry"?
I've tried linking the cell to B23 and taking the range off, but its not storing the data.
Private Sub TextBox1_Change()
Dim response As String
response = InputBox(Prompt:="Please enter the EIN/Tax Payer ID with no dashes or spaces. For security purposes this information will disappear after entry and be stored securely.", Title:="Tax Payer Data", Default:="Enter Tax Payer ID here")
Range("B23").Value = response
Exit Sub
End Sub
Is there a way to make this work on the first time, or if on the second popup have it say "please verify your entry"? I am trying to hide sensitive data (EIN, bank account number, etc) after it is entered, but keeping the starting "0"'s and the excel sheet is already formatted to show zeros. So whether we stick with the text box over the cell or something different I am open to anything.
GotFocus event should help you
Private Sub TextBox1_GotFocus()
Dim response As String
response = InputBox(Prompt:="Please enter the EIN/Tax Payer ID with no dashes or spaces. For security purposes this information will disappear after entry and be stored securely.", Title:="Tax Payer Data", Default:="Enter Tax Payer ID here")
Range("G1").Value = response
TextBox1.Text = response
Exit Sub
End Sub

Collection tracker in Excel 2017

I am trying to create a collection tracker in Excel.
I have a cell named ACCOUNT STATUS where I will display PAID or NOT PAID, and also a cell named COLLECTION STATUS where I will display OVERDUE or NOT OVERDUE.
The part where I am having problem is that on the cell named COLLECTION STATUS, I wanted to display --- if the ACCOUNT STATUS cell displayed PAID.
Here is my code:
=IF(AND(DATEDIF(Sheet1!$A3,NOW(),"d")>F3,J3="PAID"),"---",IF(AND(DATEDIF(Sheet1!$A3,NOW(),"d")<F3,J3<>"PAID"),"OVERDUE","NOT OVERDUE"))
How can I fix this?
If your formula for "Collection Status" is fully working with the exception that it doesn't display "---" whenever "Account Status" is "paid", then you can just modify your formula for "Collection Status" to this:
= IF(<account status cell> = "PAID","---",<your existing formula>)

How do I add a simple multiplication formula to excel user input box?

I have a question which I believe requires a bit of coding but I could be wrong.
I am trying to create a pdf catalog using excel and publisher together. Publisher uses the data in excel spreadsheet to automatically create a catalog.
I would like to create a user input box for clients to type a quantity (with a default value of "0").
I would like to add a formula to my user input box so that whatever number the client enters as quantity, it will multiply that value by the price in cell "C1".
I would like the default to be 0 in the input box.
If the user inputs (e.g. 5) then I would like to multiply that value by C1 (e.g. $2.99) and then display the result in a separate cell (e.g. E1)
If there is an easier way to incorporate quantity x price using excel and user input for quantity please let me know.
Than
You could use a simple UserForm with a TextBox and Label with code as below
updated for your new comment to dump to e1
Code uses cells on first worksheet.
Private Sub TextBox1_Change()
Me.Label1 = CLng(Me.TextBox1) * Sheets(1).[c1].Value
Sheets(1).[e1].Value = Me.Label1
End Sub
[
You enter the formula in the result cell. The price cell is set by you and should not be editable by the user. The quantity cell should be edited by the user.
The result cell would have a formula like '=A1*B1'. Really trivial actually.

Click event of Combobox control

I have hardcopies of 3000 invoices, in which the details of the product and the name of the dealer are available. The sales data from SAP has been exported to excel for analysis. But unfortunaltely the name of the dealer is not found in the exported data against each invoice. Hence I have decided to incorporate the dealer's name against each invoice.
For this I have embedded a Combobox Control on to the worksheet containing the sales data, to which I have loaded the names of all dealers.
To the left of the Combo control in a cell say Cells(1,1) I enter the invoice number and select the corresponding dealer as mentioned in hardcopy of the invoice from the Combo control so that with the click on the name of the dealer the name gets printed against the invoice number in the next column. To do this I have written the following macro in the Combobox1_ Click event.
Sub Combobox1_Click()
For i = 5 to 3000
If cells(1,1).value = Cells(i,4).value then
Cells(i,5).value = Combobox1.Text
End if
Next
This works fine as long as I select different dealers for each click event. But when I select the same dealer consecutively twice the click event is not triggered and the name of the dealer is not printed in the second instance.
To make the point clear say for Invoice 1233 I have selected the dealer X and the name X gets printed against invoice 1233.The next invoice 1244 also belongs to dealer X and after entering 1244 in Cells(1,1) if I select the same delaer X, the name X doesnot get printed against invoice 1244.
Please advise me resolve the problem
The click event isn't being triggered because the control hasn't detected a change. You can reset the control by changing its display value either by adding this code at the end of the click event:
ComboBox1.Text = "Select Dealer"
Or change the combobox display text only when you move away from the control, by adding this event:
Private Sub ComboBox1_LostFocus()
ComboBox1.Text = "Select Dealer"
End Sub

Resources