Colorear celda dependiendo de contenido de Textbox
Cuento con el siguiente código, lo que necesito es que al ingresar la palabra "CANCELADO" en el textbox9, la celda correspondiente a la fila 1 se coloree de rojo, caso contrario el textbox tenga otra palabra ingresada se coloree anaranjado
Private Sub CommandButton1_Click()
   Dim NombreHoja As String
    Dim HojaDestino As Range
    Dim NuevaFila As Integer
    NombreHoja = Me.ComboBox2.Value
    Set HojaDestino = ThisWorkbook.Sheets(NombreHoja).Range("A1").CurrentRegion
    NuevaFila = HojaDestino.Rows.Count + 1
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox5 = "" Or ComboBox4 = "" Or ComboBox5 = "" Then
    MsgBox "Escriba todos los datos"
Else
    Select Case ComboBox4.ListIndex
        Case 0: col = "J" ' soles
        Case 1: col = "K" ' dolares
    End Select
   With ThisWorkbook.Sheets(NombreHoja)
    .Cells(NuevaFila, 1).Value = TextBox1
    .Cells(NuevaFila, 2).Value = CDate(TextBox2)
    .Cells(NuevaFila, 3).Value = TextBox9
    .Cells(NuevaFila, 4).Value = TextBox6
    .Cells(NuevaFila, 5).Value = ComboBox2
    .Cells(NuevaFila, 6).Value = TextBox3
    .Cells(NuevaFila, 7).Value = ComboBox3
    .Cells(NuevaFila, 8).Value = TextBox4
    .Cells(NuevaFila, 9).Value = ComboBox4
    If col = "J" Then
        .Cells(NuevaFila, col).NumberFormat = "[$S/-es-PE]* #,##0.00"
    Else
        .Cells(NuevaFila, col).NumberFormat = "[$$-en-US]* #,##0.00"
    End If
    '
    .Cells(NuevaFila, col) = Val(TextBox5.Text) ' soles o dólares
    .Cells(NuevaFila, 12).Value = ComboBox5
  End With
        Sheets("FORMULARIO").Select
MsgBox "Se ha escrito correctamente su registro"
response = MsgBox("¿Desea añadir otro registro?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox9.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""
TextBox1.SetFocus
Else
Unload Me
UserForm1.Show
End If
End If
End Sub
            
            
            
        2 respuestas
                    Respuesta de Dante Amor                
                
        
        
            
                1
              
        
        
        
            
            
        
    
                
                    Respuesta de Programar Excel                
                
        
        
            
                1
              
        
        
        
            
            
        
    
                


 
        