dポイントプレゼントキャンペーン実施中!

Excelマクロについて!

検索用セルに文字を記入し、ボタンを押すと、

シート全体で記入した文字を含むセルを全て赤い太枠にするやり方が知りたいです!

よろしくお願いします!

A 回答 (2件)

罫線を操作するのって、結構、面倒なんですよね!!


マクロの記録で生成したものをちょこっと修正して作ってみましたが、ほとんどが罫線操作のコードとなっていますが、この辺は仕方ないですね。

A1セルが検索用のセルになっています。

Sub Macro1()
Application.ReplaceFormat.Clear
With Application.ReplaceFormat.Borders(xlLeft)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlThick
End With
With Application.ReplaceFormat.Borders(xlRight)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlThick
End With
With Application.ReplaceFormat.Borders(xlTop)
.Color = -16776961
.TintAndShade = 0
.Weight = xlThick
End With
With Application.ReplaceFormat.Borders(xlBottom)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlThick
End With
Cells.Replace What:=Range("A1").Value, Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
End Sub
    • good
    • 0
この回答へのお礼

わかりやすいです!!ありがとうございます!!
またなにかあればお助けください!

お礼日時:2020/11/12 08:52

自分が過去に作ったヤツそのまま


自分に合うようにカスタマイズして

Private Sub CommandButton1_Click()
Dim i As Long
Dim c As Range
Dim n As Variant
Dim cnt As Long
Dim Endrow As Long
Dim string1 As String
Dim string2 As String

Range("c3").Value = ""
If Range("c2").Value = "" Then Exit Sub

Endrow = Range("a5").End(xlDown).Row
Cells.Interior.ColorIndex = xlNone

cnt = 0
For Each c In Range("a5:a" & Endrow)
string1 = c.Text
string2 = Range("c2").Text

n = InStr(1, string1, string2, vbTextCompare)
If n <> 0 Then
Cells(c.Row, 10).Value = 1
Rows(c.Row).Interior.ColorIndex = 6
cnt = cnt + 1
Else: Cells(c.Row, 10).Value = 2

End If
Next
Range("A5:iv" & Endrow).Sort Key1:=Range("j5")
Range("j5:j65536").Value = ""
If cnt = 0 Then
Range("c3").Value = "検索文字列が存在しません"
End If

End Sub
    • good
    • 0
この回答へのお礼

勉強になりました!ありがとうございます!

お礼日時:2020/11/12 08:53

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!