Get row number when macro triggers

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello,

Slightly misleading title but I couldn't think of a better way to put it.

I have the following code:
Code:
Private Sub Worksheet_Calculate()
Const x As String = "Rate has changed"
Dim formulaColor As Long
Dim cell As Range

LinkedCells = RGB(Red:=0, Green:=0, Blue:=255)

    For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
    If InStr(1, cell.Formula, "changed") > 0 Then
    cell.Font.Color = LinkedCells
    End If

    Next
End Sub

The range in question is C4:J25 and this works perfectly.

What I'd like to do is trap the row number of the cell that has been affected by my code.

Is this possible? Or does the above need to be written slightly differently?

Thank you for reading.
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
As cell.Font.Color = LinkedCells will assign the font color to your cell, Cell.Row will retrive the cell's row number.
 
Upvote 0
As cell.Font.Color = LinkedCells will assign the font color to your cell, Cell.Row will retrive the cell's row number.

No, if I do
Code:
MsgBox Cell.Row

that loops through every cell in the range and displays a message regardless?
 
Upvote 0
Your MsgBox goes inside the If/Then loop and will show the row number of every cell having the font color changed.
But I probably missed the point, maybe you want to know the address (row) of the cell that triggered the Worksheet_Calculate event.
 
Upvote 0
Your MsgBox goes inside the If/Then loop and will show the row number of every cell having the font color changed.
But I probably missed the point, maybe you want to know the address (row) of the cell that triggered the Worksheet_Calculate event.
Yes I just need to know exactly that.

From Google it appears that once you enter the realms of Private Sub Worksheet_Calculate() then it triggers regardless of which cell is changed.

I just need to know if a formula in, say, Cx, results in a new value then tell me it was row x.
 
Upvote 0
Yes, Calculate is a global command like F9 or Shift+F9, so with it's Event there is no way to detect a specific cell.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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