repeat the same macro

  • Thread starter Thread starter Marco
  • Start date Start date
M

Marco

How can i repeat the same macro in same row and next row ?

ex
i desire repeat this macro in the same row for 5 times and after restart the
cicle in next row starting in the same previous column

Sub OrderS()

Range(ActiveCell, ActiveCell.Offset(0, 6)).Select
Selection.Sort Key1:=Range(ActiveCell, ActiveCell.Offset(0, 6)), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
ActiveCell.Offset(0, 7).Select

End Sub
for 5 times in row from C2
then 5 times again from C3

until C100 or fix range C2:C100 select / write
 
Sub ManyTimes()
Dim rng As Range
Dim iLastrow As Long
Dim i As Long, j As Long

iLastrow = Cells(Rows.Count, "C").End(xlUp).Row
For i = 2 To iLastrow
For j = 3 To 24 Step 7
OrderS Cells(i, j)
Next j
Next i

End Sub

Sub OrderS(cell As Range)
Range(cell, cell.Offset(0, 6)).Sort Key1:=Range(cell, cell.Offset(0,
6)), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top