message prompts in VBA

VBAmalta89

Board Regular
Joined
Mar 25, 2011
Messages
116
I have a user form and I need to check a value of a cell in a particular worksheet when the user inputs chooses data from a combo box.

If the value of this cell in the worksheet is >0 then a message is prompted otherwise the program can continue normally.

How can i do this in VBA?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can use the ComboBox's Change event procedure. But which cell on which worksheet do you want to check?
 
Upvote 0
the sheet is called calculator and the cell B34

so the code will be under such a sub right?

Private Sub FactoryNum_Change()

and then i create a message box...right?
 
Upvote 0
Like this:

Code:
Private Sub FactoryNum_Change()
    If Worksheets("calculator").Range("B34").Value <= 0 Then
        MsgBox "B34 must be greater than zero."
        Exit Sub
    End If
'   More code
End Sub
 
Upvote 0
what if the value that needs to be checked in the worksheet varies depending on the option from the dropbox?

is there a way of doing something similar?
 
Upvote 0
Consider the following example in a worksheet called components:

Column A Column B
24 90
25 (blank)
26 76
27 89
28 (blank)

Now the combo box drops down the data in column A.

I need the user form to prompt a message if when a value chosen from the drop down box has a corresponding value in column B. after pressing an OK button then the user can continue inputting data in the user form. So it is sort of a warning message only. If the value in column B is blank then no message is prompted.
 
Upvote 0
Try:

Code:
Private Sub FactoryNum_Change()
    With FactoryNum
        If Range(.RowSource).Cells(.ListIndex + 1, 2).Value <= 0 Then
            MsgBox Range(.RowSource).Cells(.ListIndex + 1, 2).Address(False, False) & " must be greater than zero."
            Exit Sub
        End If
    End With
'   More code
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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
Back
Top