Función "Si" que compara entre dos valores en vba

Como escribo en VBA la función Si (If) que me compara entre dos valores, por ejemplo:

If  Range ("L"& i).Value <1.025 and Range ("L"& i).Value <1.000 Then

Else If

End if

1 respuesta

Respuesta
1

H o l a:

Puedes poner cuáles son los ejemplos, y qué esperas cómo resultado, si el valor cumple con las 2 condiciones qué se debe hacer y si no cumplo qué debe hacer.

En tu línea pones si es menor a 1.025 y si es menor a 1.000, con esas condiciones solamente los valores menores a 1.000 son los que se cumplen.

¿Después tienes EseIf significa que vas a poner otra condición?

Porque no mejor me explicas qué es lo que necesitas y te preparo la macro.

Hola Dante, te remito el código.

Sub Color_Celdas_Potencia()

' Acceso directo: Ctrl+Mayús+U
'
Dim i As Integer

For i = 9 To 14
If Range("I" & i).Value >= 1.025 Then
'Color Rojo Letra Blanca
Range("I" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Else
'Color ladrillo Letra Negra
If Range("I" & i).Value < 1.025 Then
If Range("I" & i).Value > 1 Then
Range("I" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 26367
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I" & i).Value <= 1 Then
If Range("I" & i).Value > 0.97 Then
'Color Verde Letra Negra
Range("I" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I" & i).Value <= 0.97 Then
If Range("I" & i).Value > 0.95 Then
'Color Verde Claro Letra Negra
Range("I" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I" & i).Value <= 0.95 Then
'Color Limón Letra Negra
Range("I" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 6479588
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End If
End If
End If
End If
Next
Range("G3").Select
End Sub

H o l a:

Pero tienes que explicarme con ejemplos qué es lo que necesitas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas