Senso
Inventaris
- Lid geworden
- 13 jun 2016
- Berichten
- 11.273
- Besturingssysteem
- W10 Pro en W11 Pro
- Office versie
- Office 2007 H&S en Office 2021 Prof Plus
Wat is het bereik zoals het in de code staat?
Stel ik wil een bereik van A1 tm Z500, hoe wordt dan de regel in VBA?
Highlighting the Row and Column that Contain the Active Cell, Within the Current Region
The following code example clears the color in all the cells on the worksheet by setting the ColorIndex property equal to 0, and then highlights the row and column that contain the active cell, within the current region by using the CurrentRegion property of the Range object.
VB
Stel ik wil een bereik van A1 tm Z500, hoe wordt dan de regel in VBA?
Highlighting the Row and Column that Contain the Active Cell, Within the Current Region
The following code example clears the color in all the cells on the worksheet by setting the ColorIndex property equal to 0, and then highlights the row and column that contain the active cell, within the current region by using the CurrentRegion property of the Range object.
VB
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
If IsEmpty(Target) Or Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
With ActiveCell
' Highlight the row and column that contain the active cell, within the current region
Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Interior.ColorIndex = 8
Range(Cells(.CurrentRegion.Row, .Column), Cells(.CurrentRegion.Rows.Count + .CurrentRegion.Row - 1, .Column)).Interior.ColorIndex = 8
End With
Application.ScreenUpdating = True
End Sub
Laatst bewerkt: