Skip to content

Instantly share code, notes, and snippets.

@aaronhoffman
Last active July 3, 2018 13:03
Show Gist options
  • Select an option

  • Save aaronhoffman/5c465e2500190454dfd6c97a1ec1e0a5 to your computer and use it in GitHub Desktop.

Select an option

Save aaronhoffman/5c465e2500190454dfd6c97a1ec1e0a5 to your computer and use it in GitHub Desktop.
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
@aaronhoffman
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment