VBA to read cell value rather than the cell formula

austicks84

New Member
Joined
May 8, 2018
Messages
11
I would like a message box to pop up when a cell in a range changes. The cells in the range all have IF formulas in them. My problem is that the code i am using seems to only read the formula, which doesn't change, hence nothing happens. How can i get my code to read the cell value, which does change, rather than the formula which doesn't?

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Range("ED45:EO83"), Target) Is Nothing) Then
MsgBox "Cell " & Target.Address & " has changed.", vbInformation, "Kutools for Excel"
End If
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi

How does the cell value change?
The event procedure is only fired when the cell is written.

Please elaborate.
 
Upvote 0
Hi
To detect formula changes, use the Worksheet_Calculate event

dave
 
Upvote 0
To detect formula changes, use the Worksheet_Calculate event

Hi Dave

The Worksheet_Calculate event will run when any calculation is performed. You'd then have to figure out what exactly happened.
The Worksheet_Change event will tell you which cell was modified which seems to be in this case more efficient and direct.
 
Upvote 0
The Worksheet_Calculate event will run when any calculation is performed. You'd then have to figure out what exactly happened.
The Worksheet_Change event will tell you which cell was modified which seems to be in this case more efficient and direct.

thanks but I am fully aware event does not have Target Parameter - there are workarounds using Calculate event - just waiting for OPs response

Dave
 
Last edited:
Upvote 0
Do you mean like in the below?

Private Sub Worksheet_Change(ByVal Target As Range)

If Not (Application.Intersect(Range("ED45:EO83"), Target) Is Nothing) Then
MsgBox "Cell.value " & Target.Address & " has changed.", vbInformation, "Kutools for Excel"
End If
End Sub
 
Upvote 0
Do i just change the below?:

Private Sub Worksheet_
Calculate(ByVal Target As Range)
If Not (Application.Intersect(Range("ED45:EO83"), Target) Is Nothing) Then
MsgBox "Cell " & Target.Address & " has changed.", vbInformation, "Kutools for Excel"
End If
End Sub
 
Upvote 0
Do i just change the below?:

Private Sub Worksheet_
Calculate(ByVal Target As Range)
If Not (Application.Intersect(Range("ED45:EO83"), Target) Is Nothing) Then
MsgBox "Cell " & Target.Address & " has changed.", vbInformation, "Kutools for Excel"
End If
End Sub

Worksheet_Calculate event has no parameters & you cannot (as far as I am aware) modify then in manner shown.

To detect which cell in your range has changed using this event, a workaround is to use the Range.ID property to store the cell value which you use to compare changes against

try following

Code:
Private Sub Worksheet_Calculate()
    Dim rng As Range, cell As Range
    Dim CellHasChanged As Boolean
    
    Set rng = Me.Range("ED45:EO83")
    For Each cell In rng.Cells
        With cell
           CellHasChanged = CBool(.ID <> .Value)
           If CellHasChanged Then
            .ID = .Value
            MsgBox "Cell " & cell.Address & " has changed.", vbInformation, "Cell Value Changed"
            Exit For
           End If
        End With
    Next cell
    Set rng = Nothing
End Sub

A slight limitation of this approach is that the values stored in ID property are lost when workbook closed but hopefully, will not be an issue for you.


Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top