このマクロはありますが、特定のシート(この場合は "aaa"、 "bbb"、 "ccc")でのみ検索を実行することはできません。\ 現在のコードはMsgBox "No紫色の欄が見つかりました」と言っていました。 私はまた、(現在他のシートが開いていても)最初に見つかったセルを選択して表示するためのマクロです。 助けてください。特定のシートで検索する
Dim cell As Range
Dim SearchRange As Range
Dim c As Range
Dim shtfound As Boolean
sthfound = False
On Error Resume Next
Set SearchRange = ThisWorkbook.Worksheets(Array("bbb", "aaa", "ccc")).UsedRange.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not SearchRange Is Nothing Then
With Application.FindFormat.Interior
.PatternColorIndex = xlAutomatic
.Color = 16711935
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Set c = SearchRange.Find(What:="", After:=SearchRange.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True)
If Not c Is Nothing Then
firstAddress = c.Address
Set foundrange = c
Do
Set c = SearchRange.Find(What:="", After:=c, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True)
Set foundrange = Union(foundrange, c)
Loop While Not c Is Nothing And c.Address <> firstAddress
foundrange.Activate
sthfound = True
MsgBox "Purple fields found: " & foundrange.Count
End If
End If
If sthfound = False Then MsgBox "No purple field found"
End Sub
なぜシートをループしないのですか?ループ内の各範囲を検索しますか? –
Shai Radoさんが提案したのと同じことをお勧めします – Siva
どういう意味ですか? – Pawel