VBA ค้นหาสีแดง
Posted: Tue Jul 17, 2018 1:25 pm
ต้องการค้นหาสีแดงครับ ค้นหาแบบ Find Next ไปทีล่ะอัน วนไปเรื่อยๆ
Code: Select all
Sub SelectColoredCells()
Dim rCell As Range
Dim lColor As Long
Dim rColored As Range
lColor = RGB(255, 0, 0)
Set rColored = Nothing
For Each rCell In Selection
If rCell.Interior.Color = lColor Then
If rColored Is Nothing Then
Set rColored = rCell
Else
Set rColored = Union(rColored, rCell)
End If
End If
Next
If rColored Is Nothing Then
MsgBox "No cells match the color"
Else
rColored.Select
MsgBox "Selected cells match the color:" & _
vbCrLf & rColored.Address
End If
Set rCell = Nothing
Set rColored = Nothing
End Sub