Last active
July 3, 2018 13:03
-
-
Save aaronhoffman/5c465e2500190454dfd6c97a1ec1e0a5 to your computer and use it in GitHub Desktop.
Microsoft Excel Find Next Value Change in Column Macro https://aaron-hoffman.blogspot.com/2010/12/microsoft-excel-find-next-value-change.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub FindNextValueChangeInColumn() | |
| ' | |
| ' FindNextValueChangeInColumn Macro | |
| ' | |
| On Error GoTo ErrHandler | |
| Dim currentValue As String | |
| Dim compareValue As String | |
| currentValue = ActiveCell.Value | |
| If (currentValue = "") Then | |
| ' Value is blank, this could mean we are at the bottom of all the values | |
| ' use xlDown for performance | |
| Selection.End(xlDown).Select | |
| Else | |
| ' select next cell down (priming read) | |
| ActiveCell.Offset(1, 0).Select | |
| compareValue = ActiveCell.Value | |
| Do While currentValue = compareValue | |
| ActiveCell.Offset(1, 0).Select | |
| compareValue = ActiveCell.Value | |
| Loop | |
| End If | |
| Exit Sub | |
| ErrHandler: | |
| Exit Sub | |
| End Sub | |
| Sub FindPreviousValueChangeInColumn() | |
| ' | |
| ' FindPreviousValueChangeInColumn Macro | |
| ' | |
| On Error GoTo ErrHandler | |
| Dim currentValue As String | |
| Dim compareValue As String | |
| currentValue = ActiveCell.Value | |
| If (currentValue = "") Then | |
| ' Value is blank, this could mean we are at the top of all the values | |
| ' use xlUp for performance | |
| Selection.End(xlUp).Select | |
| Else | |
| ' select next cell down (priming read) | |
| ActiveCell.Offset(-1, 0).Select | |
| compareValue = ActiveCell.Value | |
| Do While currentValue = compareValue | |
| ActiveCell.Offset(-1, 0).Select | |
| compareValue = ActiveCell.Value | |
| Loop | |
| End If | |
| Exit Sub | |
| ErrHandler: | |
| Exit Sub | |
| End Sub |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related blog post here: https://aaron-hoffman.blogspot.com/2010/12/microsoft-excel-find-next-value-change.html