ciao
questo codice funziona solo se non ci sono formattazioni condizionali
(le elimina tutte)
ma hai detto sfondo perciò dovrebbe andare.
scrivi 1 in cella A1 (ma poi puoi cambiare cella tranquillamente)
evidenzio solo cella attiva
sul foglio
Dim OldX
Dim OldY
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Celle As String
Dim formato As Integer
formato = 0
formato = Cells.FormatConditions.Count
If formato <> 0 Then
Cells.FormatConditions.Delete
End If
'Calcolo le colonne
OldX = Target.Column
OldY = Target.Row
'Impostazione Formattazione condizionale Cella selzionata
Cells(OldY, OldX).FormatConditions.Add Type:=xlExpression, Formula1:="=$A$1=1"
Cells(OldY, OldX).FormatConditions(1).Borders(xlLeft).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlLeft).Color = RGB(170, 0, 0)
Cells(OldY, OldX).FormatConditions(1).Borders(xlRight).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlRight).Color = RGB(170, 0, 0)
Cells(OldY, OldX).FormatConditions(1).Borders(xlTop).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlTop).Color = RGB(0, 0, 170)
Cells(OldY, OldX).FormatConditions(1).Borders(xlBottom).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlBottom).Color = RGB(0, 0, 170)
'Colore sfondo
Cells(OldY, OldX).FormatConditions(1).Interior.ColorIndex = 36
End Sub
evidenzio cella e bordo riga colonna
Dim OldX
Dim OldY
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Celle As String
Dim formato As Integer
formato = 0
formato = Cells.FormatConditions.Count
If formato <> 0 Then
Cells.FormatConditions.Delete
End If
'Calcolo le colonne
OldX = Target.Column
OldY = Target.Row
'Impostazione Formattazione condizionale Verticale
Range("A:A").Offset(0, OldX - 1).FormatConditions.Add Type:=xlExpression, Formula1:="=$A$1=1"
Range("A:A").Offset(0, OldX - 1).FormatConditions(1).Borders(xlLeft).LineStyle = xlContinuous
Range("A:A").Offset(0, OldX - 1).FormatConditions(1).Borders(xlLeft).Color = RGB(170, 0, 0)
Range("A:A").Offset(0, OldX - 1).FormatConditions(1).Borders(xlRight).LineStyle = xlContinuous
Range("A:A").Offset(0, OldX - 1).FormatConditions(1).Borders(xlRight).Color = RGB(170, 0, 0)
'eliminazione formattazione cella selezionata
Cells(OldY, OldX).FormatConditions.Delete
'Impostazione Formattazione condizionale Orizzontale
Range("1:1").Offset(OldY - 1, 0).FormatConditions.Add Type:=xlExpression, Formula1:="=$A$1=1"
Range("1:1").Offset(OldY - 1, 0).FormatConditions(1).Borders(xlTop).LineStyle = xlContinuous
Range("1:1").Offset(OldY - 1, 0).FormatConditions(1).Borders(xlTop).Color = RGB(0, 0, 170)
Range("1:1").Offset(OldY - 1, 0).FormatConditions(1).Borders(xlBottom).LineStyle = xlContinuous
Range("1:1").Offset(OldY - 1, 0).FormatConditions(1).Borders(xlBottom).Color = RGB(0, 0, 170)
'eliminazione formattazione cella selezionata
Cells(OldY, OldX).FormatConditions.Delete
'Impostazione Formattazione condizionale Cella selzionata
Cells(OldY, OldX).FormatConditions.Add Type:=xlExpression, Formula1:="=$A$1=1"
Cells(OldY, OldX).FormatConditions(1).Borders(xlLeft).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlLeft).Color = RGB(170, 0, 0)
Cells(OldY, OldX).FormatConditions(1).Borders(xlRight).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlRight).Color = RGB(170, 0, 0)
Cells(OldY, OldX).FormatConditions(1).Borders(xlTop).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlTop).Color = RGB(0, 0, 170)
Cells(OldY, OldX).FormatConditions(1).Borders(xlBottom).LineStyle = xlContinuous
Cells(OldY, OldX).FormatConditions(1).Borders(xlBottom).Color = RGB(0, 0, 170)
'Colore sfondo
Cells(OldY, OldX).FormatConditions(1).Interior.ColorIndex = 36
End Sub
poi qualche esperto potrà
variartelo eliminando solo la formattazione specifica.
[Modificato da federico460 16/06/2019 06:53]