ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Do while not last row (https://www.excelbanter.com/excel-worksheet-functions/246478-do-while-not-last-row.html)

littleredhairedgirl

Do while not last row
 
Here's a loop I'm trying to excute that moves items in a column into
rows. I can't figure out completely how to set the loop to go under
that last row.


Sub Macro100()
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
cnt = 4
Do While [not last row]
dst = cnt - 1
Range("A" & cnt).Select
Selection.Cut Destination:=Range("B" & dst)
Range("A" & cnt + 1).Select
Selection.Cut Destination:=Range("C" & dst)
Range("A" & cnt + 2).Select
Selection.Cut Destination:=Range("D" & dst)
Range("A" & cnt + 3).Select
Selection.Cut Destination:=Range("E" & dst)
Range("A" & cnt + 4).Select
Selection.Cut Destination:=Range("F" & dst)
Range("A" & cnt + 5).Select
Selection.Cut Destination:=Range("G" & dst)
cnt = cnt + 7
End


End Sub

littleredhairedgirl

Do while not last row
 
On Oct 24, 6:29*am, littleredhairedgirl
wrote:
Here's a loop I'm trying to excute that moves items in a column into
rows. I can't figure out completely how *to set the loop to go under
that last row.

Didn't get the Loop in there right...


Sub Macro100()

Dim a As Integer, x As Integer
cnt = 4
x = Cells(Rows.Count, "A").End(xlUp).Row
For a = 1 To x

dst = cnt - 1
Range("A" & cnt).Select
Selection.Cut Destination:=Range("B" & dst)
Range("A" & cnt + 1).Select
Selection.Cut Destination:=Range("C" & dst)
Range("A" & cnt + 2).Select
Selection.Cut Destination:=Range("D" & dst)
Range("A" & cnt + 3).Select
Selection.Cut Destination:=Range("E" & dst)
Range("A" & cnt + 4).Select
Selection.Cut Destination:=Range("F" & dst)
Range("A" & cnt + 5).Select
Selection.Cut Destination:=Range("G" & dst)
cnt = cnt + 7

Next a

End Sub

Mike H

Do while not last row
 
Hi,

Maybe this

Sub Macro100()
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
dst = 3
For x = 4 To lngLastRow Step 7
Range("A" & x).Cut Destination:=Range("B" & dst)
Range("A" & x + 1).Cut Destination:=Range("C" & dst)
Range("A" & x + 2).Cut Destination:=Range("D" & dst)
Range("A" & x + 3).Cut Destination:=Range("E" & dst)
Range("A" & x + 4).Cut Destination:=Range("F" & dst)
Range("A" & x + 5).Cut Destination:=Range("G" & dst)
dst = dst + 1
Next
End


End Sub

Mike

"littleredhairedgirl" wrote:

Here's a loop I'm trying to excute that moves items in a column into
rows. I can't figure out completely how to set the loop to go under
that last row.


Sub Macro100()
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
cnt = 4
Do While [not last row]
dst = cnt - 1
Range("A" & cnt).Select
Selection.Cut Destination:=Range("B" & dst)
Range("A" & cnt + 1).Select
Selection.Cut Destination:=Range("C" & dst)
Range("A" & cnt + 2).Select
Selection.Cut Destination:=Range("D" & dst)
Range("A" & cnt + 3).Select
Selection.Cut Destination:=Range("E" & dst)
Range("A" & cnt + 4).Select
Selection.Cut Destination:=Range("F" & dst)
Range("A" & cnt + 5).Select
Selection.Cut Destination:=Range("G" & dst)
cnt = cnt + 7
End


End Sub
.



All times are GMT +1. The time now is 09:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com