PDA

View Full Version : Help with activecell and a message box



lexluther88
11-12-2006, 01:51 PM
First, the code will check to see if the ActiveCell selected is in the second column that contains the product names - column 2. If the column is not 2, show a message box with title "Error" and message "You need to select a product in the second column." Also, have the code quit out of the subprocedure after showing the message.

I'm trying this:



If ActiveCell.Value <> Cell(2) Then
msgBox "You need to select a product in the second colum", "Error"

End If



How can I a code to quit out of the subprocedure after showing the message. Also is "<>" the symbol used for "not equal to?" I checked online, and as simple as it seems, nothing has given me an answer for a not equal to sign...
Any help would be appreciated, thanks!

Norie
11-12-2006, 01:59 PM
That code doesn't make much sense I'm afraid.

What exactly is Cell?

Where is the code located?

When/how is it meant to be triggered?

lexluther88
11-12-2006, 02:17 PM
Sorry-
column 2 meaning the B column, specifically cells B5 through B25..but if I can somehow generalize that the active cell must be in the B column, otherwise you get that message box. The command is triggered when the Private Sub cmdSelect_Click(), (select button) is clicked.. First a product must be selected in the B column, then the user hits the select button, in which the active cell must be in that column, otherwise they get the message box.

mdmackillop
11-12-2006, 02:42 PM
Private Sub cmdSelect_Click()
If Intersect(ActiveCell, Range("B5:B25")) Is Nothing Then
MsgBox "You need to select a product in the second column", vbCritical
Exit Sub
End If
'Do something
MsgBox ActiveCell.Address
End Sub

lexluther88
11-12-2006, 02:59 PM
Thanks a lot, mdmackillop!, works like a charm!