I have these values in my excel spreadsheet from A1:C6
1 6 1
2 2 6
3 34 2
4 5 4
5 1 6
6 5 5
I am using the vba code below to select all cells with 6:
Sub test()
Dim rng As Range
Set rng = Range("A1:C6")
Dim newRng As Range
For Each cell In rng
cell.Select
If cell.Value = 6 Then
If Not newRng Is Nothing Then
newRng = Union(newRng, Range(cell.Address))
Else
Set newRng = Range(cell.Address)
End If
End If
Next cell
newRng.Select
End Sub
but newRng.select is only selecting one cell and that is B1.
What am I doing wrong?
Bookmarks