• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Track Total # of Value Changes in a Cell |VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Track Total # of Value Changes in a Cell |VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosTrack Total # of Value Changes in a…
sp_PrintTopic sp_TopicIcon
Track Total # of Value Changes in a Cell
Avatar
Patrick McGettigan

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
May 14, 2020
sp_UserOfflineSmall Offline
1
October 2, 2020 - 11:46 pm
sp_Permalink sp_Print

Hello -

I am trying to develop a Column in my spreadsheet that tracks the number of changes in the cells of another Column. Specifically in this example:

Column H triggers a formula in the cells of Column I (when H3 says "Yes", I3 populates with the date) - each time the value in I3 changes, I want J3's value to grow by 1. I want this to be possible whether the change is formula-driven or manual. I have the below VBA as a starting point, but it doesn't trigger properly when the first change is driven by a formula and it also begins populating the J cells with a 0 rather than a 1. 

tracker-tally-layout.PNGImage Enlarger

Option Explicit

Private Sub Worksheet_Change _
( _
ByVal Target As Range _
)

Const s_CheckColumn As String = "I:I"
Const s_CountColumn As String = "J:J"

If Intersect(Target, Range(s_CheckColumn)) Is Nothing Then Exit Sub

Dim rngCell As Range
For Each rngCell In Intersect(Target, Range(s_CheckColumn))
With Range(s_CountColumn).Cells(rngCell.Row)
.Value2 = IIf(.Value2 <> vbNullString, .Value2 + 1, IIf(rngCell.Value2 <> vbNullString, 0, vbNullString))
End With
Next rngCell

End Sub

sp_PlupAttachments Attachments
  • sp_PlupImage tracker-tally-layout.PNG (11 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
October 3, 2020 - 7:10 pm
sp_Permalink sp_Print

Hi Patrick,

Your formula in Col I was referencing itself - you should have been given warnings by Excel about 'circular references' when you opened the file?

I've moved the logic/functionality of what you were doing with the formula in Col I to VBA.

Also, when you are using worksheet events you should turn off events in the event sub with Application.EnableEvents = False so that the changes you make with your own code don't trigger another event and force the code to run again.

Please see attached file for my VBA.  Note that if the cell in Col H contains "Yes" and you click the cell and choose "Yes" again that triggers the event code and the count in Col J will increase.

Option Explicit

Private Sub Worksheet_Change _
( _
ByVal Target As Range _
)

Const s_CheckColumn As String = "H:H"
Const s_CountColumn As String = "J:J"

If Intersect(Target, Range(s_CheckColumn)) Is Nothing Then Exit Sub

Application.EnableEvents = False

Dim rngCell As Range

Target.Offset(0, 1).Value = Now()
Target.Offset(0, 2).Value = Target.Offset(0, 2).Value + 1

Application.EnableEvents = True

End Sub

 

Regards

Phil

The following users say thank you to Philip Treacy for this useful post:

Purfleet
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, Dario Serrati, Valentyn Kristioglo, Nada Perovic, Andrew Er
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27279

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.