2017-08-07 9 views
-3

を強調Iは 複数の列中に存在してもよい テキスト文字列の複数枚(カラムJ範囲カラムAで言う)探索全体Excelワークブックとセル

を含む全体のExcel workbookを検索する必要があります

テキスト文字列が見つかると、セルにカラーフォーマットが適用されます。

これが可能ですか、それとも1枚ごとにルールを作成する必要がありますか?

例:

  • 検索文字列「情報」どこでも私のworkbookと形式のセルで青

私が入るように複数の異なるテキスト文字列を持っており、それぞれが異なる色のフォーマットを持つことになります。
これらをすべて1つのルールで組み合わせる方法はありますか?それとも、それぞれのテキスト・ストリングごとに同じルールを使用して、それぞれに新しいルールを作成させるだけですか?

私はExcelの条件付き書式では本当に新しいので、あなたが優しく、それぞれのステップを踏んでくれれば幸いです。

私はoracleインターネットを検索し、この解決策を見つけました。私はそれをテストする必要があるが、それは私が必要とするものを行うかもしれない。

これは、ChooseColorsというテーブルを作成する必要があります。最初の列は検索文字列、2番目の列は使用可能な範囲の色です。 検索領域が2番目のシートにあります - このシートから開始します。

コード:

Sub DoColors() 
Dim Picker As Variant 
Dim Colors As Variant 
Dim Rws As Long, j As Long 
Dim i As Integer 
Dim Sht As String 
Dim c As Range 
Dim FirstAddress 

Sht = ActiveSheet.Name 
'load search strings and colors into arrays 
Application.Goto Reference:="ChooseColors" 
ReDim Picker(1 To Selection.Rows.Count) 
ReDim Colors(1 To Selection.Rows.Count) 
For i = 1 To Selection.Rows.Count 
Picker(i) = ActiveCell.Value 
Colors(i) = ActiveCell.Offset(0, 1).Interior.ColorIndex 
ActiveCell.Offset(1, 0).Select 
Next i 
'search the test range, changing backgrounds as required 
Sheets(Sht).Activate 
For i = 1 To UBound(Picker) 
With Cells.SpecialCells(xlCellTypeConstants, xlTextValues) 
    Set c = .Find(Picker(i), LookIn:=xlValues) 
    If Not c Is Nothing Then 
     FirstAddress = c.Address 
     Do 
      c.Interior.ColorIndex = Colors(i) 
      Set c = .FindNext(c) 
     Loop While Not c Is Nothing And c.Address <> FirstAddress 
    End If 
End With 
Next i 

End Sub 
+0

新しい色の新しい条件は新しいルールである必要があります –

+0

[excel-vba]で質問にタグを付けると、 VBAソリューション? – Luuklag

+0

これは間違いなくマクロが必要です。 VBAはここに救助する! :D – Jaberwocky

答えて

0

このコードは、あなたが投稿したコードの最初のセットに基づいて、あなたは、ブック内で入力するものは何でもテキストのすべての出現を強調表示します。


Public Sub find_highlight() 

    'Put Option Explicit at the top of the module and 
    'Declare your variables. 
    Dim FindString As String 
    Dim wrkSht As Worksheet 
    Dim FoundCell As Range 
    Dim FirstAddress As String 

    FindString = InputBox("Information") 

    'Use For...Each to cycle through the Worksheets collection. 
    For Each wrkSht In ThisWorkbook.Worksheets 
     'Find the first instance on the sheet. 
     Set FoundCell = wrkSht.Cells.Find(_ 
      What:=FindString, _ 
      After:=wrkSht.Range("A1"), _ 
      LookIn:=xlValues, _ 
      LookAt:=xlWhole, _ 
      SearchOrder:=xlByRows, _ 
      SearchDirection:=xlNext, _ 
      MatchCase:=False) 
     'Check it found something. 
     If Not FoundCell Is Nothing Then 
      'Save the first address as FIND loops around to the start 
      'when it can't find any more. 
      FirstAddress = FoundCell.Address 
      Do 
       With FoundCell.Interior 
        .ColorIndex = 6 
        .Pattern = xlSolid 
        .PatternColorIndex = xlAutomatic 
       End With 
       'Look for the next instance on the same sheet. 
       Set FoundCell = wrkSht.Cells.FindNext(FoundCell) 
      Loop While FoundCell.Address <> FirstAddress 
     End If 

    Next wrkSht 

End Sub 

は、複数の値を検索すると、フォーマットは次のコードを使用することができます。
Infoという名前のシートに依存し、A1:A3の範囲で検索する値があります。
これらの値の背景は、必要に応じて色付けされており、コードは一致する値を見つけて色をコピーします。
enter image description here

さらに多くの値を許可するためにコードを追加したり、動的名前付き範囲を使用してソース値を返すことができます。
動的名前付き範囲は、特定の名前「SourceValues」を持つ=Info!$A$1:INDEX(Info!$A:$A,COUNTA(Info!$A:$A))などの式で構成されます。
FormulaリボンでDefine Nameを選択し、数式をRefers To:ボックスに、SourceValuesを名前に貼り付けます。
enter image description here
あなたはその後、Set Information = Range("SourceValues")

Public Sub find_highlight() 

    'Put Option Explicit at the top of the module and 
    'Declare your variables. 
    Dim FindString As String 
    Dim wrkSht As Worksheet 
    Dim FoundCell As Range 
    Dim FirstAddress As String 
    Dim InfoBit As Range 
    Dim Information As Range 

    Set Information = Range("SourceValues") 
    'Set Information = ThisWorkbook.Worksheets("Info").Range("A1:A3") 

    'Use For...Each to cycle through the information we're looking for. 
    For Each InfoBit In Information 
     'Use For...Each to cycle through the Worksheets collection. 
     For Each wrkSht In ThisWorkbook.Worksheets 
      'Ignore the "Info" sheet as it holds our values to search for. 
      If wrkSht.Name <> "Info" Then 
       'Find the first instance on the sheet. 
       Set FoundCell = wrkSht.Cells.Find(_ 
        What:=InfoBit, _ 
        After:=wrkSht.Range("A1"), _ 
        LookIn:=xlValues, _ 
        LookAt:=xlWhole, _ 
        SearchOrder:=xlByRows, _ 
        SearchDirection:=xlNext, _ 
        MatchCase:=False) 
       'Check it found something. 
       If Not FoundCell Is Nothing Then 
        'Save the first address as FIND loops around to the start 
        'when it can't find any more. 
        FirstAddress = FoundCell.Address 
        Do 
         'Copy all formatting - bit of screen flicker. 
'      InfoBit.Copy 
'      FoundCell.PasteSpecial Paste:=xlPasteFormats 

         'Just copy the Interior colour. 
         FoundCell.Interior.Color = InfoBit.Interior.Color 

         'Look for the next instance on the same sheet. 
         Set FoundCell = wrkSht.Cells.FindNext(FoundCell) 
        Loop While FoundCell.Address <> FirstAddress 
       End If 
      End If 
     Next wrkSht 
    Next InfoBit 

End Sub 

enter image description here

+0

ありがとうございます。私が与えた最初の例は、特定の文字列を1つだけ見つけましたが、複数の文字列を検索し、複数の異なる色を適用するコードが必要です。私が上に投稿したものは「半分」働いています。私はこの行にエラーが表示されていますが、理由はわかりません。ループしないでください。何もありません。c.Address <> FirstAddress – Craig

+0

複数の文字列を検索するコードを追加しました。これらの複数の文字列を含む新しいシートを追加するだけです。 –

+0

ダーレンありがとう、私はこれを修正して複数の文字列を含む方法を少し失ってしまった。 – Craig

0

と範囲を参照したい私はそれが必要とされる優れたVBAソリューションのためのすべてだ...しかし、ここにあなたが使用してオフに優れています検索+置換(Ctrl + H/Cmd + H)。 [オプション]ボタンをクリックし、置換の横に置き換えるテキストを書式設定することができます。 「フォーマット」を選択し、青色を入力します。検索と置換の両方のフィールドに「情報」を入れて実行してください:)

+1

ありがとう、はい、1つの文字列で動作しますが、私は複数の文字列と複数の異なる色に適用する必要があります。それを言って、時間が私はおそらく私が見つけると置換することができた可能性がVBAのコードを見つけるために取った。 – Craig

関連する問題