Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:02:20+00:00 2026-06-07T23:02:20+00:00

I googled around, and I wrote the following code that I want to run

  • 0

I googled around, and I wrote the following code that I want to run only when a specific cell, D4, changes:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
    Static EmailSent As Boolean
    Dim Threshold As Integer
    Dim Cell As String, Email As String, Msg As String

    Cell = "D4"
    Threshold = 100
    Email = Range("E7").Value


    Set KeyCells = Range(Cell)

    If Not Application.Intersect(Range(Cell), Range(Target.Address)) Is Nothing Then
        Dim x As Integer
        x = Range(Cell).Value

        If x >= Threshold Then
            EmailSent = False
        ElseIf x < Threshold And Not EmailSent Then
            EmailSent = True
            Msg = "You only have " & x & " widgets remaining."
            MsgBox Msg
            SendMail Email, Msg
        End If
    End If
End Sub

This works, and I know there are a lot of similar questions here. But here’s where I’m having trouble: this only works if I set D4 to an explicit value, say "48". I want it to work even if D4 is a formula: so if D4 is "=SUM(A4:C4)" then an email should send if that sum drops below 100. This code won’t send an email in that case 🙁

Does anyone know how to fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:02:23+00:00Added an answer on June 7, 2026 at 11:02 pm
    Private Sub Worksheet_Calculate()
        CheckForMail
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        CheckForMail Target
    End Sub
    
    
    Sub CheckForMail(Optional rng As Range = Nothing)
    
        Static EmailSent As Boolean
        Dim KeyCells As Range
        Dim Threshold As Integer
        Dim Cell As String, Email As String, Msg As String
        Dim x As Integer
    
        Cell = "D4"
        Set KeyCells = Me.Range(Cell)
    
        'if called from worksheet_change, check the range
        If Not rng Is Nothing Then
            If Application.Intersect(KeyCells, rng) Is Nothing Then
                Exit Sub
            End If
        End If
    
        Threshold = 100
        Email = Me.Range("E7").Value
        x = KeyCells.Value
    
        If x >= Threshold Then
            EmailSent = False
        ElseIf x < Threshold And Not EmailSent Then
            EmailSent = True
            Msg = "You only have " & x & " widgets remaining."
            MsgBox Msg
            SendMail Email, Msg
        End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I googled around and learned that Lift encourages view-first development, lazy loading of entities,
I have searched/Googled around but I'm struggling with the following problem. I am building
I wrote some code that spits out an image. The code ran on my
I have some code that I wrote to implement a vertical swipe on a
I wrote a Google Chrome extension and the site that I want to use
I want to fitbound pushpins to visible all around user's location pushpin. i wrote
I already googled around to find a solution for my need, with no success.
I've googled around but couldn't find a working MongoDB viewer or data browser. An
I've googled around everywhere, but cannot find much for rendering strings to textures and
I've just recently learned about friend class concept in C++ (I've googled around for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.