Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Select All Cells that Match a Selected Cell - Excel VBA Macro
'Excel macro that will select all of the cells that match the value contained in the currently selected cell.
Sub SelectAllThatMatch()
Set sourceCell = ActiveCell
Set selectedCells = sourceCell
Dim rwIndex As Integer
Dim rwMax As Integer
rwMax = ActiveSheet.UsedRange.Rows.Count
Dim colIndex As Integer
Dim colMax As Integer
colMax = ActiveSheet.UsedRange.Columns.Count
For rwIndex = 1 To rwMax
For colIndex = 1 To colMax
If Cells(rwIndex, colIndex).Value = sourceCell.Value Then
Set selectedCells = Application.Union(selectedCells, Cells(rwIndex, colIndex))
End If
Next colIndex
Next rwIndex
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment