Skip to content

Instantly share code, notes, and snippets.

Embed
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
selectedCells.Select
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment