Consulting

Results 1 to 5 of 5

Thread: Help with activecell and a message box

  1. #1

    Help with activecell and a message box

    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:

    [VBA]

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

    End If

    [/VBA]

    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!

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    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?

  3. #3
    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.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]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[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Thanks a lot, mdmackillop!, works like a charm!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •