+ Reply to Thread
Results 1 to 10 of 10

Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

  1. #1
    Registered User
    Join Date
    12-19-2019
    Location
    New York
    MS-Off Ver
    365
    Posts
    4

    Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Can someone please help? I have a sheet and am trying to add a VBA code that triggers a pop up message if a person enters a number in cell E5 that is less than 0.5. I have the following code entered in the Microsoft Visual Basic for Applications:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Range("$E$5").Value < 0.5 Then MsgBox "This is wrong"

    End Sub

    It seems to be working, as when I enter a value in E5 that is less than 0.5 that alert comes up. However, the alert comes up for every single cell in the spreadsheet when I enter a value less than 0.5. I thought I had restricted it to cell E5 in the coding.

    Could someone please help me and let me know what I am doing wrong? THANK YOU!!!!

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Welcome to the forum. Please use Code Tags when posting code. (check Forum Rule #2)


    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Another (just slightly different) way:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    12-19-2019
    Location
    New York
    MS-Off Ver
    365
    Posts
    4

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    that worked!!! thank you!!!

  5. #5
    Registered User
    Join Date
    12-19-2019
    Location
    New York
    MS-Off Ver
    365
    Posts
    4

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Any ideas why this isn't working now? I have attempted to add tags...I hope these are correct! When I enter this into the Microsoft Visual Basic for Application, save, and then test in the excel I'm getting the attached pop up as an error and I don't know what needs to be fixed! THANK YOU!!!

    Please Login or Register  to view this content.
    Attached Images Attached Images
    Last edited by sfranklin; 12-20-2019 at 09:36 AM. Reason: added tags

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Requested code tags added by moderator, as the OP is new.


    What isn't working ? When testing the msgboxes come up just fine
    Last edited by AliGW; 12-20-2019 at 06:53 AM.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    A code is useless just using the Excel Data Validation ! …

  8. #8
    Registered User
    Join Date
    12-19-2019
    Location
    New York
    MS-Off Ver
    365
    Posts
    4

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Can you have the message box pop up with data validation? I thought for the message box I need to do VBA coding. Thanks!!

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Trying to add simple VBA code on one cell and it's applying to whole sheet!!!

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Quote Originally Posted by sfranklin View Post
    Can you have the message box pop up with data validation?
    Yes, it's an Excel Basics …

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. need asistance applying a simple formula to a formatted cell
    By dan_fash in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-04-2016, 07:55 PM
  2. Applying two simple formulas and an edit whenever a row has a missing cell
    By AntiPivotTable in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 05:55 PM
  3. VBA Code to select the first cell after applying Filter
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2015, 07:31 AM
  4. vba code for copying data to cell and applying macro (drop down list)
    By Tamjeed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2014, 10:57 AM
  5. Applying a simple formula for each cell in column?
    By boltoncalling in forum Excel General
    Replies: 2
    Last Post: 01-05-2012, 10:57 AM
  6. Replies: 1
    Last Post: 05-13-2010, 07:51 PM
  7. Applying a simple macro over 100 documents
    By FouTight in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-19-2007, 12:01 PM

Tags for this Thread

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