Select All Cells that Match a Selected Cell - Excel VBA Macro
This file contains 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
'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