+ Reply to Thread
Results 1 to 13 of 13

Message Box for range of cells

Hybrid View

  1. #1
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Message Box for range of cells

    I got great help from Cheeky Charlie in my last thread - thanks!

    In cell E12, I have a drop down list of choices. I am using a code that will display a message box whenever a particular choice is picked from that list.
    If Target.Address = "$E$12" Then
    Application.DisplayAlerts = False
    ActiveSheet.Unprotect
        Select Case Range("E12").Value
            Case "OPTION D": MsgBox ("MESSAGE MESSAGE MESSAGE MESSAGE")
            End Select
    ActiveSheet.Protect
    Application.DisplayAlerts = True
    End If
    I'm trying to do the same thing in a large range of cells (L5:O5, L12:O12, L15:O15, L18:O18, L21:O21 and L24:O24). So if someone were to choose OPTION A from cell L5, they'd get a message. If they chose OPTION A from cell M18, they'd get the same message. If the chose OPTION A from cell O21, they'd get the same message. If they chose...well, you get the idea.

    My question, is do I have to have a copy of that code for every single cell I want to do this in, or is there a way to make that same code cover the range of cells I specified?

    Thanks!



    Sorry, forgot to mention that I'm using Office Excel 2003
    Last edited by Ryusui; 10-20-2009 at 06:11 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Message Box for range of cells

    Maybe like this:
    Private Sub Worksheet_Change(ByVal Target As Range)
        With Target
            If .Count > 1 Then Exit Sub
            If Not Intersect(.Cells, Me.Range("L5:O5,L12:O12,L15:O15,L18:O18,L21:O21,L24:O24")) Is Nothing Then
                If UCase(.Value) = "OPTION D" Then MsgBox "whatever"
            End If
        End With
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Hmm, nothing happens when I try that code.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Message Box for range of cells

    It has to go in the appropriate sheet module.

  5. #5
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Oh, I did that. It was placed in the module for the sheet in which the drop down cells are. Still no joy. =(

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Message Box for range of cells

    Macros enabled? Tried closing and reopening? If it still doesn't work, post a sanitized workbook.

  7. #7
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Yup, macros are enabled. The other ones I have in there run fine. Posted the code and saved, closed and then opened to test, but no luck.

    What do you mean by a "sanitized workbook"?

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Message Box for range of cells

    One in which any sensitive information has been removed.

  9. #9
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Well if that wasn't just obvious. Forgive my lack of common sense this morning. Too many interruptions.

    Here ya go.
    Attached Files Attached Files

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Message Box for range of cells

    The code I posted doesn't appear in your workbook.

  11. #11
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Sorry, I took it out when it wasn't working. And I guess I uploaded the wrong copy.

    But in the meantime, I was playing around with the sheet and here's something I discovered. When I copy your code exactly and change OPTIOND to the actual value I want, the code doesn't work. But if I change one of the values in the range to OPTIOND and leave the code's value as OPTIOND, then the code works. Is there something else I was supposed to change in that code?
    -------------------------

    EDIT:
    I think I figured it out. And I think it's cause I might have thrown you off, and if so, I'm sorry! But if my value is anything in all caps, then it'll work. I just tried doing "OptionD" in my value list and in the code and it failed to execute. But when I changed the code and value in the list to THISVALUE, it worked.
    How can I change it so that it'll take something like "J&J Smith"?
    Last edited by Ryusui; 10-20-2009 at 06:00 PM.

  12. #12
    Registered User
    Join Date
    09-03-2008
    Location
    Kahului, HI
    MS-Off Ver
    365 v.2409
    Posts
    47

    Re: Message Box for range of cells

    Brilliant! It worked! By changing the code to "J&J SMITH", I was still able to leave the value itself as "J&J Smith" and it worked!
    Still, I find it weird because in that code I posted in my initial post, I have the VBA code as Title Case, and it works fine. This is the only one that's done in all uppercase.

    But hey, as long as it works!


    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1