Soy nuevo en VBA, pero bastante bueno con PHP. Dicho esto, estoy luchando con circuitos de VBA ...Cómo bucle de filas con macro de Excel VBA?
que tienen esta hoja con 40 filas, denominadas "SH1":
SH1
A B C D E
1 2 One 1.0a 12
2 7 Two 2.0b 34
3 13 Three 3.0c 56
4 14 Four 4.0d 78
..
40
necesito colocar a través de 40 filas y compruebe el valor de la columna A. Si el valor en la columna A cumple mis criterios (ver a continuación), genere algunos resultados y póngalos en otra hoja.
Mi hoja de salida es de 3 columnas y llamado "SH2":
SH2
A B C D E
1 1.0a 12 One
2.0b 34 Two
2 3.0c 56 Three
4.0d 78 Four
..
15
Mi criterio para decidir dónde va:
// First loop:
if a1 < 8, put c1 in SH2 a1, put d1 in SH2 b1, put b1 in SH2 c1
if a2 < 8, put c2 in SH2 a1, put d2 in SH2 b1, put b2 in SH2 c1
// ... loop through a40 ...
continuación:
// Second loop:
if a1 > 8 AND a1 < 16, put c1 in SH2 a2, put d1 in SH2 b2, put b1 in SH2 c2
if a2 > 8 AND a2 < 16, put c2 in SH2 a2, put d2 in SH2 b2, put b2 in SH2 c2
// ... loop through a40 ...
PROGRESO EDITAR:
Parece estar funcionando, pero ¿se pregunta si hay una manera "más limpia"?
Sub CatchersPick2()
Dim curCell As Range
For Each curCell In Sheet4.Range("C3:C40").Cells
If curCell.Value > 0 And curCell.Value < 73 Then
cLeft = cLeft _
& curCell.Offset(0, 5) & "." _
& curCell.Offset(0, 6) & vbLf
cMidl = cMidl _
& curCell.Offset(0, -2) & ", " _
& curCell.Offset(0, -1) & " " _
& curCell.Offset(0, 7) & vbLf
cRght = cRght _
& curCell.Offset(0, 9) & " " _
& curCell.Offset(0, 2) & " " _
& curCell.Offset(0, 11) & " " _
& curCell.Offset(0, 10) & vbLf
End If
Next curCell
Sheet6.Range("B3") = cLeft
Sheet6.Range("C3") = cMidl
Sheet6.Range("D3") = cRght
Sheet6.Range("B3:D3").Rows.AutoFit
Sheet6.Range("B3:D3").Columns.AutoFit
End Sub
Lo sentimos, pero que se ve bastante desordenado y no parece coincidir con el material anterior. Por cierto, dices 'si a2> 8 AND a1 <16 'quieres decir si' a2> 8 AND a2 <16' (segundo ciclo, línea 2). ¿Quieres hacer las cosas anteriores (primero, segundo lopp)? – Fionnuala
Mi material anterior fue solo un ejemplo basado en la salida simple que necesito generar. Mi ejemplo anterior está funcionando, pero siendo nuevo en los bucles y variables de VBA, estoy seguro de que hay una manera más limpia (¡AYUDA!). Para responder a su pregunta, "sí", eso fue un error tipográfico. – Jeff