メインコンテンツへスキップ

データが満載された広範な Excel ワークシートをナビゲートするのは困難な場合があり、場所を見失ったり、値を読み間違えたりすることがよくあります。 データ分析を強化し、エラーの可能性を減らすために、Excel で選択したセルの行と列を動的に強調表示する 3 つの方法を紹介します。 セルからセルに移動すると、強調表示が動的に変化し、次のデモに示すように、正しいデータに集中し続けるための明確で直感的な視覚的な手がかりが提供されます。

Excel でアクティブな行と列を自動強調表示する


ビデオ: Excel でアクティブな行と列を自動ハイライトする


VBA コードを使用してアクティブな行と列を自動ハイライトする

現在のワークシートで選択したセルの列全体と行全体を自動的に強調表示するには、次の VBA コードがこのタスクの実行に役立ちます。

ステップ 1: アクティブな行と列を自動ハイライトするワークシートを開きます。

ステップ 2: VBA シート モジュール エディターを開き、コードをコピーします。

  1. シート名を右クリックして、 コードを表示 コンテキストメニューから、スクリーンショットを参照してください。
  2. 開いた VBA シート モジュール エディターで、次のコードをコピーして空のモジュールに貼り付けます。 スクリーンショットを参照してください:
    VBAコード:選択したセルの行と列を自動ハイライトします
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Update by Extendoffice
        Dim rowRange As Range
        Dim colRange As Range
        Dim activeCell As Range
        Set activeCell = Target.Cells(1, 1)
        Set rowRange = Rows(activeCell.Row)
        Set colRange = Columns(activeCell.Column)
         Cells.Interior.ColorIndex = xlNone
        rowRange.Interior.Color = RGB(248, 150, 171)
        colRange.Interior.Color = RGB(173, 233, 249)
    End Sub
    
    ヒント: コードをカスタマイズする
    • ハイライトの色を変更するには、次のスクリプトで RGB 値を変更するだけです。
      rowRange.Interior.Color = RGB(248、150、171)
      ColRange.Interior.Color = RGB(173、233、249)
    • 選択したセルの行全体のみを強調表示するには、次の行を削除するかコメントアウト (先頭にアポストロフィを追加) します。
      ColRange.Interior.Color = RGB(173, 233, 249)
    • 選択したセルの列全体のみを強調表示するには、次の行を削除するかコメントアウト (先頭にアポストロフィを追加) します。
      rowRange.Interior.Color = RGB(248, 150, 171)

  3. 次に、VBA エディタ ウィンドウを閉じてワークシートに戻ります。

結果:

ここで、セルを選択すると、そのセルの行と列全体が自動的に強調表示され、以下のデモに示すように、選択したセルの変化に応じて強調表示が動的に移動します。

注意:
  • このコードは、ワークシート内のすべてのセルから背景色をクリアするため、カスタムの色が設定されたセルがある場合は、このソリューションの使用を避けてください。
  • このコードを実行すると、 アンドゥ シート内の機能です。つまり、 を押しても間違いを元に戻すことはできません。 Ctrlキー+ Z ショートカット。
  • このコードは、保護されたワークシートでは機能しません。
  • 選択したセルの行と列の強調表示を停止するには、以前に追加した VBA コードを削除する必要があります。 その後、 をクリックして強調表示をリセットします。 ホーム > 塗りつぶしの色 > 塗りつぶしなし.

Kutoolsをワンクリックするだけでアクティブな行と列を自動ハイライトします

Excel の VBA コードの制限に直面していますか? クツール Excel用's グリッドフォーカス 機能は理想的なソリューションです。 VBA の欠点に対処するように設計されており、シートのエクスペリエンスを向上させるさまざまな強調表示スタイルを提供します。 これらのスタイルを開いているすべてのワークブックに適用できるため、 クツール 一貫して効率的で視覚的に魅力的なデータ管理プロセスを保証します。

Note:こんな場合はこちらをご利用ください グリッドフォーカス 特徴を教えてください Kutools for Excelをダウンロードしてインストールします 最初。

インストールした後 Kutools for Excel、をクリックしてください クツール > グリッドフォーカス この機能を有効にするには、 これで、アクティブ セルの行と列がすぐに強調表示されることがわかります。 この強調表示は、セルの選択を変更すると、それに応じて動的に移動します。 以下のデモをご覧ください。

グリッド フォーカス機能の主な利点:
  • 元のセルの背景色を保持します。
    VBA コードとは異なり、この機能はワークシートの既存の書式設定を尊重します。
  • 保護されたシートで使用可能:
    この機能は、保護されたワークシート内でシームレスに動作するため、セキュリティを損なうことなく機密文書や共有文書を管理するのに最適です。
  • 元に戻す機能には影響しません。
    この機能を使用すると、Excel の元に戻す機能に完全にアクセスできます。 これにより、変更を簡単に元に戻すことができ、データ操作に安全性が追加されます。
  • 大規模なデータでも安定したパフォーマンス:
    この機能は、大規模なデータセットを効率的に処理できるように設計されており、複雑でデータ量の多いスプレッドシートでも安定したパフォーマンスを保証します。
  • 複数の強調表示スタイル:
    この機能にはさまざまな強調表示オプションが用意されており、さまざまなスタイルや色から選択して、行、列、または行と列のアクティブ セルを、好みやニーズに最適な方法で目立たせることができます。
ヒント:

条件付き書式設定を使用してアクティブな行と列を自動強調表示する

Excel では、アクティブな行と列を自動的に強調表示するように条件付き書式を設定することもできます。 この機能を設定するには、次の手順に従ってください。

ステップ 1: データ範囲を選択する

まず、この機能を適用するセルの範囲を選択します。 これは、ワークシート全体または特定のデータセットである可能性があります。 ここではワークシート全体を選択します。

ステップ 2: 条件付き書式設定にアクセスする

ホーム > 条件付き書式 > 新しいルール、スクリーンショットを参照してください:

ステップ 3: 新しい書式設定ルールで操作を設定する

  1. 新しい書式設定規則 ダイアログボックスで、 式を使用して、フォーマットするセルを決定する ルールタイプを選択します リストボックス。
  2. この数式が真であるときの書式値 ボックスに、これらの数式のいずれかを入力します。この例では、XNUMX 番目の数式を適用して、アクティブな行と列を強調表示します。
    アクティブな行を強調表示するには:
    =CELL("row")=ROW()
    アクティブな列を強調表示するには:
    =CELL("col")=COLUMN()
    アクティブな行と列を強調表示するには:
    =OR(CELL("row")=ROW(), CELL("col")= COLUMN())
  3. 次に、をクリックします。 フォーマット
  4. 以下では セルの書式設定 ダイアログボックス、下 埋める タブで、必要に応じて XNUMX つの色を選択してアクティブな行と列を強調表示します。スクリーンショットを参照してください。
  5. 次に、をクリックします。 OK > OK ダイアログを閉じます。

結果:

これで、セル A1 の列全体と行全体が一度に強調表示されたことがわかります。 この強調表示を別のセルに適用するには、目的のセルをクリックして、 F9 キーを押してシートを更新すると、新しく選択したセルの列全体と行全体が強調表示されます。

ヒント: 
  • 確かに、Excel で強調表示するための条件付き書式設定のアプローチは解決策を提供しますが、それは使用するほどシームレスではありません。 VBA & グリッドフォーカス 特徴。 この方法では、シートを手動で再計算する必要があります (再計算するには、 F9 キー)。
    ワークシートの自動再計算を有効にするには、単純な VBA コードをターゲット シートのコード モジュールに組み込むことができます。 これにより、更新プロセスが自動化され、別のセルを選択すると、キーを押さなくても強調表示がすぐに更新されます。 F9 鍵。 シート名を右クリックし、選択してください コードを表示 コンテキストメニューから。 次に、次のコードをコピーしてシート モジュールに貼り付けます。
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Target.Calculate
    End Sub
    
  • 条件付き書式設定では、ワークシートに手動で適用した既存の書式設定が保持されます。
  • 条件付き書式設定は、特に非常に大規模なデータセットに適用される場合、不安定であることが知られています。 これを広範囲に使用すると、ワークブックのパフォーマンスが低下し、データ処理とナビゲーションの効率に影響を与える可能性があります。
  • CELL 関数は Excel バージョン 2007 以降でのみ使用でき、このメソッドは以前のバージョンの Excel とは互換性がありません。

上記の方法の比較

特徴 VBAコード 条件付き書式 Kutools for Excel
セルの背景色を保持する いいえ 有り 有り
元に戻すをサポート いいえ 有り 有り
大規模なデータセットでも安定 いいえ いいえ 有り
保護されたシートでも使用可能 いいえ 有り 有り
開いているすべてのワークブックに適用されます 現在のシートのみ 現在のシートのみ 開いているすべてのワークブック
手動更新が必要です (F9) いいえ 有り いいえ

Excel で選択したセルの列と行を強調表示する方法に関するガイドはこれで終わりです。 Excel のヒントやテクニックをさらに詳しく知りたい場合は、当社の Web サイトで何千ものチュートリアルをご覧ください。 ここをクリックしてアクセスしてください。 読んでいただきありがとうございます。今後さらに役立つ情報を提供できることを楽しみにしています。


関連記事:

  • アクティブセルの行と列を自動ハイライトします
  • 多数のデータを含む大きなワークシートを表示する場合は、選択したセルの行と列を強調表示して、データを簡単かつ直感的に読み取って誤読しないようにすることができます。 ここでは、現在のセルの行と列を強調表示するためのいくつかの興味深いトリックを紹介します。セルが変更されると、新しいセルの列と行が自動的に強調表示されます。
  • Excel で XNUMX つおきの行または列を強調表示する
  • 大きなワークシートでは、XNUMX 行おき、または n 行おきまたは n 列ごとに強調表示または塗りつぶしを行うと、データの可視性と読みやすさが向上します。 ワークシートの見た目がすっきりするだけでなく、データをより早く理解するのにも役立ちます。 この記事では、XNUMX 行おきまたは n 行おきに網掛けをするさまざまな方法を説明し、データをより魅力的でわかりやすい方法で表示できるようにします。
  • スクロール中に全体/行全体を強調表示する
  • 複数の列を持つ大きなワークシートがある場合、その行のデータを区別するのは困難です。 この場合、アクティブセルの行全体を強調表示して、水平スクロールバーを下にスクロールしたときにその行のデータをすばやく簡単に表示できるようにすることができます。この記事では、この問題を解決するためのいくつかの秘訣について説明します。 。
  • ドロップダウンリストに基づいて行を強調表示します
  • この記事では、ドロップダウンリストに基づいて行を強調表示する方法について説明します。たとえば、次のスクリーンショットを撮ります。列Eのドロップダウンリストから[進行中]を選択すると、この行を赤い色で強調表示する必要があります。ドロップダウンリストから[完了]を選択すると、この行を青色で強調表示する必要があります。[未開始]を選択すると、緑色を使用して行が強調表示されます。
Comments (61)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
And please reply to an email
This comment was minimized by the moderator on the site
Great job . But in the first task at the top of the browser page, when I did it, it was working correctly, but when I made protection for the sheet, it stopped working correctly, you see, what's the solution. Thank you
This comment was minimized by the moderator on the site
Hello,
To solve your problem, please apply the followign code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rowRange As Range
    Dim colRange As Range
    Dim activeCell As Range
    Me.Unprotect
    Cells.Interior.ColorIndex = xlNone
    Set activeCell = Target.Cells(1, 1)
    Set rowRange = Rows(activeCell.Row)
    Set colRange = Columns(activeCell.Column)
    rowRange.Interior.Color = RGB(173, 233, 249)
    colRange.Interior.Color = RGB(173, 233, 249)
    Me.Protect
End Sub



Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    
    ' Clear previous highlighting
    Me.Cells.FormatConditions.Delete
    
    ' Check if Checkbox1 is checked
    ' If CheckBox1.Value = True Then
        ' Check if a single cell or a range of cells is selected
        If Target.Cells.Count = 1 Or Target.Cells.Count > 1 Then
            Dim selectedRange As Range
            Dim selectedRows As Range
            Dim selectedColumns As Range
            
            Set selectedRange = Target
            Set selectedRows = Me.Range(Me.Cells(selectedRange.Row, 1), Me.Cells(selectedRange.Row + selectedRange.Rows.Count - 1, 1).EntireRow)
            Set selectedColumns = Me.Range(Me.Cells(1, selectedRange.Column), Me.Cells(1, selectedRange.Column + selectedRange.Columns.Count - 1).EntireColumn)
            
            ' Add conditional formatting to highlight the selected rows
            With selectedRows.FormatConditions.Add(Type:=xlExpression, Formula1:="=TRUE")
                .Interior.Color = RGB(255, 230, 153) ' Yellow color
            End With
            
            ' Add conditional formatting to highlight the selected columns
            With selectedColumns.FormatConditions.Add(Type:=xlExpression, Formula1:="=TRUE")
                .Interior.Color = RGB(255, 230, 153) ' Yellow color
            End With
        End If
    ' End If
    
    On Error GoTo 0
End Sub
This comment was minimized by the moderator on the site
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next

' Clear previous highlighting
Me.Cells.FormatConditions.Delete

' Check if a single cell or a range of cells is selected
If Target.Cells.Count = 1 Or Target.Cells.Count > 1 Then
Dim selectedRange As Range
Dim selectedRows As Range
Dim selectedColumns As Range

Set selectedRange = Target
Set selectedRows = Me.Range(Me.Cells(selectedRange.Row, 1), Me.Cells(selectedRange.Row + selectedRange.Rows.Count - 1, 1).EntireRow)
Set selectedColumns = Me.Range(Me.Cells(1, selectedRange.Column), Me.Cells(1, selectedRange.Column + selectedRange.Columns.Count - 1).EntireColumn)

' Add conditional formatting to highlight the selected rows
With selectedRows.FormatConditions.Add(Type:=xlExpression, Formula1:="=TRUE")
.Interior.Color = RGB(255, 230, 153) ' Yellow color
End With

' Add conditional formatting to highlight the selected columns
With selectedColumns.FormatConditions.Add(Type:=xlExpression, Formula1:="=TRUE")
.Interior.Color = RGB(255, 230, 153) ' Yellow color
End With
End If

On Error GoTo 0
End Sub
This comment was minimized by the moderator on the site
can you please post code in VBA format? trying to figure out what your code looks like from what you posted in a jumble is frustrating.
This comment was minimized by the moderator on the site
Hi,

The above code is brilliant. But i have two questions and if you can help then will be much appreciated. Let me know if there is cost associated with it.

1. The above code is removing my previous formatting of the cells. Eg. if i have got the cells filld with blue then above code clears that fill.
2. Is there a code that i can use when i am extracting values from another sheet and that row in the that sheet gets highlighted as well. Eg. I want to extract vale from another cell, so when i press = sign in sheet 1 and then when i move to sheet 2 to bring the value the row in the sheet doesn't get highlighted.

Regards,
This comment was minimized by the moderator on the site
Hello, Patel
For the first question:
It may be difficult to modify the VBA code, so, I recommend you to apply the Conditional Formatting feature for solving this problem, the following article may help you:
https://www.extendoffice.com/documents/excel/3500-excel-highlight-selected-row-conditional-formatting.html

Or you can use the Kutools for Excel' Reading Layout feature, you can try it 30 days for free.
Please download from: https://www.extendoffice.com/download/kutools-for-excel.html

For the second question:
Sorry, I can't solve this problem at present,😜
This comment was minimized by the moderator on the site
How do you modify the code so that:
1. It does not permanently strip existing colors of cells. Currently, after another cell is selected, it leaves colorless previous row. I'd like to keep the colors of the worksheet, as they were before row was highlighted by this code.
2. Limit the highlight width to only Columns A thru K, not the entire row.
This comment was minimized by the moderator on the site
Hello,
It may be difficult to modify the VBA code, so, here, I recommend you to apply the Conditional Formatting feature for solving this problem, please view the below article: (Note: if you need to highlight the column A to column K, you just need to select the range you need, and then apply the conditional formatting.)
https://www.extendoffice.com/documents/excel/3500-excel-highlight-selected-row-conditional-formatting.html


Or you can use the Kutools for Excel' Reading Layout feature, you can try it 30 days for free.
Please download from: https://www.extendoffice.com/download/kutools-for-excel.html

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Thank you so much for this tip!!!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Another easy way to highlight your rows: https://youtu.be/iOF06mZDGIk
This comment was minimized by the moderator on the site
FAIL. Wiped out all my other cell formatting irreversibly. And doesn't work if the sheet is protected. FAIL.
This comment was minimized by the moderator on the site
Hi Gues,The code does not work in a protected worksheet. If you want to keep the original cell formatting, please try the below code.The Reading Layout feature of Kutools is stable and handy, maybe you can download a free trial to have a try.
<div data-tag="code">Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'Update 202001106
Static xRow
Static xColumn

Dim xWs As Worksheet
Dim xCRg, xCRg1, xRRg, xRRg1, xOHRg As Range
Dim xAHRORg, xAHRORg1 As Range
Dim xAWs As Worksheet
Dim xFNum As Integer
Dim xCll As Range

On Error Resume Next

Application.ScreenUpdating = False
pRow = Selection.Row
pColumn = Selection.Column

Set xWs = ActiveWorkbook.Worksheets.Item("AutoHighlightRAndC")
Set xAWs = Target.Worksheet
If xWs Is Nothing Then
Set xWs = ActiveWorkbook.Worksheets.Add
xWs.Name = "AutoHighlightRAndC"
xWs.Visible = xlSheetHidden
xAWs.Activate
End If

If xColumn <> "" Then
Set xCRg = Columns(xColumn)
xCRg.Interior.ColorIndex = xlNone
Set xCRg = Intersect(xCRg.Worksheet.UsedRange, xCRg)
For xFNum = 1 To xCRg.Count
Set xAHRORg1 = xAWs.Cells(xFNum, xColumn)
Set xAHRORg = xWs.Cells(xFNum, xColumn)
xAHRORg1.Interior.ColorIndex = xAHRORg.Interior.ColorIndex
'xCRg.Item(xFNum).Interior.ColorIndex = xWs.Columns(xColumn).Item(xFNum).Interior.ColorIndex
Next

Set xRRg = Rows(xRow)
xRRg.Interior.ColorIndex = xlNone
Set xRRg = Intersect(xCRg.Worksheet.UsedRange, xCRg)
For xFNum = 1 To xRRg.Count
Set xAHRORg1 = xAWs.Cells(xRow, xFNum)
Set xAHRORg = xWs.Cells(xRow, xFNum)
xAHRORg1.Interior.ColorIndex = xAHRORg.Interior.ColorIndex
'xRRg.Item(xFNum).Interior.ColorIndex = xWs.Rows(xRow).Item(xFNum).Interior.ColorIndex
Next

End If

xRow = pRow
xColumn = pColumn

Set xCRg = Columns(pColumn)
Set xCRg1 = Intersect(xCRg.Worksheet.UsedRange, xCRg)
For xFNum = 1 To xCRg1.Count
Set xOHRg = xWs.Cells(xFNum, pColumn)
xOHRg.Interior.ColorIndex = xCRg1.Item(xFNum).Interior.ColorIndex
Next

Set xRRg = Rows(pRow)
Set xRRg1 = Intersect(xRRg.Worksheet.UsedRange, xRRg)

For xFNum = 1 To xRRg1.Count
Set xCll = xWs.Cells(pRow, xFNum)
xCll.Interior.ColorIndex = xRRg1.Item(xFNum).Interior.ColorIndex
Next
xCRg.Interior.ColorIndex = 34
xRRg.Interior.ColorIndex = 34
Application.ScreenUpdating = True
End Sub
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations