PDA

View Full Version : Select only cells with visible values



DougR21
08-22-2021, 09:49 PM
Hi! I have a column with filled cells and blank cells because of the IFERROR function. I would like to select only cells with visible values ​​but the macro code selects all cells in the range. How could I only select cells with visible values ​​in the range?

arnelgp
08-22-2021, 10:21 PM
Private Sub test()
Const the_range As String = "B1"
Dim rng As String
Dim i As Integer
With ActiveSheet
For i = 1 To Range(the_range).SpecialCells(xlCellTypeLastCell).Row
If Len(.Cells(i, 2)) <> 0 Then
rng = rng & .Cells(i, 2).Address & ","

End If
Next
If Len(rng) Then
rng = Left$(rng, Len(rng) - 1)
.Range(rng).Select
End If
End With

End Sub