+ Reply to Thread
Results 1 to 9 of 9

VBA to show certain text when a number is entered into a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    86

    VBA to show certain text when a number is entered into a cell

    Hello Everyone

    I need help with some VBA to show a message in a text box when a number is entered into a cell. There are 6 different pieces of text depending on which number is entered.

    Any help would be great!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello jiminic,

    Is this TextBox on a UserForm or Worksheet? What are the six values to display, and what are the numbers?

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    86
    Hi Leith

    Thanks for your response. this is in a worksheet and the numbers are ranging as follows:

    <21,
    >21 but <30,
    >31 but <40,
    >41 but <50,
    >51 but <60, and
    >60

    Thank you again

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello jiminic,

    You could use the Select Case statement for this.
    Select Case ActiveCell.Value
      Case <21
        Msg = "Less than 21"
      Case 22 To 30
        Msg = "Between 22 and 29"
      Case 32 To 39 
        Msg = "Between 32 and 39"
      Case  42 To 49
        Msg = "Bewteen 42 and 49"
      Case 52 and 59
        Msg = "Between 52 and 59"
      Case >60
        Msg = "Greater than 60"
    End Select
    
    MsgBox Msg
    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    86
    Thank you Leith

    One last question though, where do I put the code, and how do I make it so that when the number is entered into a specific cell, eg: E38, that the message box appears?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello jiminc,

    Do you have a range of cells this will apply to?

    Thanks,
    Leith Ross

+ 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