Ciclo for en excel vba filas

Tengo el siguiente código: para la fila 6 y 7 lo que requiero hacer es poder recorrer las filas sin ir copiando el código nuevamente como en el ejemplo:
'FILA 6
If Range("e6") = 1 And IsEmpty(Range("f6").Value) = True And IsEmpty(Range("g6").Value) = True And IsEmpty(Range("h6").Value) = True Then
Range("F6").Select
ActiveCell.FormulaR1C1 = "3"
Range("G6").Select
ActiveCell.FormulaR1C1 = "2"
Range("H6").Select
ActiveCell.FormulaR1C1 = "1"
ElseIf Range("e6") = 2 And Range("f6") = Empty And Range("g6") = Empty And Range("h6") = Empty Then
Range("F6").Select
ActiveCell.FormulaR1C1 = "1"
Range("G6").Select
ActiveCell.FormulaR1C1 = "3"
Range("H6").Select
ActiveCell.FormulaR1C1 = "2"
ElseIf Range("e6") = 3 And Range("f6") = Empty And Range("g6") = Empty And Range("h6") = Empty Then
Range("F6").Select
ActiveCell.FormulaR1C1 = "2"
Range("G6").Select
ActiveCell.FormulaR1C1 = "1"
Range("H6").Select
ActiveCell.FormulaR1C1 = "3"
End If
'FILA 7
If Range("e7") = 1 And IsEmpty(Range("f7").Value) = True And IsEmpty(Range("g7").Value) = True And IsEmpty(Range("h7").Value) = True Then
Range("F7").Select
ActiveCell.FormulaR1C1 = "3"
Range("G7").Select
ActiveCell.FormulaR1C1 = "2"
Range("H7").Select
ActiveCell.FormulaR1C1 = "1"
ElseIf Range("e7") = 2 And Range("f7") = Empty And Range("g7") = Empty And Range("h7") = Empty Then
Range("F7").Select
ActiveCell.FormulaR1C1 = "1"
Range("G7").Select
ActiveCell.FormulaR1C1 = "3"
Range("H7").Select
ActiveCell.FormulaR1C1 = "2"
ElseIf Range("e7") = 3 And Range("f7") = Empty And Range("g7") = Empty And Range("h7") = Empty Then
Range("F7").Select
ActiveCell.FormulaR1C1 = "2"
Range("G7").Select
ActiveCell.FormulaR1C1 = "1"
Range("H7").Select
ActiveCell.FormulaR1C1 = "3"
End If

Respuesta
1

podemos usa for each o select case 

Podría mostranos una imagen para ver lo que requiere y donde irían copiado los datos

1 respuesta más de otro experto

Respuesta
1

Prueba lo siguiente:

Sub test_1()
  Dim i As Long
  For i = 6 To Range("E" & Rows.Count).End(3).Row
    If Range("F" & i) & Range("G" & i) & Range("H" & i) = "" Then
      Select Case Range("E" & i).Value
        Case 1: Range("F" & i).Resize(1, 3).Value = Array(3, 2, 1)
        Case 2: Range("F" & i).Resize(1, 3).Value = Array(1, 2, 3)
        Case 3: Range("F" & i).Resize(1, 3).Value = Array(2, 1, 3)
      End Select
    End If
  Next
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas