Aprende con los siguientes ejemplos a utilizar los ciclos:
For ... Next Do ... Loop While For Each ... NextCódigo 1:
-----------------------
Sub ciclo_For()Dim i As LongFor i = 1 To Range("A" & Rows.Count).End(3).RowIf Range("A" & i).Value = "SUMA" ThenRows(i).Copy Sheets("Hoja2").Range("A" & Rows.Count).End(3)(2)End IfNextEnd Sub
-----------------------
Código 2:
-----------------------
Sub Ciclo_While()Dim f As RangeDim celda As StringSet f = Range("A:A").Find("SUMA", , xlValues, xlWhole)If Not f Is Nothing Thencelda = f.AddressDoRows(f.Row).Copy Sheets("Hoja2").Range("A" & Rows.Count).End(3)(2)Set f = Range("A:A").FindNext(f)Loop While celda <> f.AddressEnd IfEnd Sub
-----------------------
Código 3:
-----------------------
Sub Ciclo_For_Each()Dim ar As RangeFor Each ar In Range("A1", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeConstants).AreasRows(ar.Cells(ar.Rows.Count).Row).Copy Sheets("Hoja2").Range("A" & Rows.Count).End(3)(2)NextEnd Sub
-----------------------
No hay comentarios.:
Publicar un comentario