Excel

VBA

by Andrea Spera

Formattazione condizionale
Un esempio di formattazione condizionale con VBA.
Codice
Public Sub EsempioFormattazione()
	Dim V_row As Integer
	Dim V_cut As Integer
	Dim Color1, Color2 As Integer
		V_row = 2
		V_cut = Range("H2").Value
		Color1 = Range("H3").Interior.ColorIndex
		Color2 = Range("H4").Interior.ColorIndex
	While Cells(V_row, 5).Value <> ""
		If Cells(V_row, 5) > V_cut Then
			Range(Cells(V_row, 1), Cells(V_row, 5)).Interior.ColorIndex = Color1
		Else
			Range(Cells(V_row, 1), Cells(V_row, 5)).Interior.ColorIndex = Color2
		End If
		V_row = V_row + 1
	Wend
	Exit Sub
End Sub
Public Sub ResetFormattazione()
	Dim V_row As Integer
		V_row = 2
	While Cells(V_row, 5).Value <> ""
		Range(Cells(V_row, 1), Cells(V_row, 5)).Interior.ColorIndex = 0
		V_row = V_row + 1
	Wend
	Exit Sub
End Sub
La macro colora l'intera riga della tabella in base al valore della colonna E:E. Il file di esempio è scaricabile dal link qui sotto.
Scaricando il seguente file accettate che viene rilasciato così com'è senza alcun tipo di garanzia.