Mike
Mike

Reputation: 2751

Add worksheets for every day of the month looping in ascending order

My loop works, but it's putting them in reverse order. I realize it's doing exactly what I have below, but I'm not good enough with the syntax yet.I can't figure out how to reverse it.

Current worksheet order is descending: 3.31, 3.30, 3.29, etc...

I need ascending order: 3.21, 3.22, 3.23, 3.24, etc...

days = numerical value days of each month mon = numerical value of month

Suggestions?

For i = 1 To Val(days)
    Sheets(1).Copy after:=Sheets(1)
    ActiveSheet.Name = mon & "." & (i)
Next i

Upvotes: 0

Views: 612

Answers (1)

Peter Albert
Peter Albert

Reputation: 17475

This will place the sheets in the correct order at the end of your workbook:

For i = 1 To Val(days)
    Sheets(1).Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = mon & "." & (i)
Next i

This will place them correctly after sheet1:

Set wsTemp = Sheets(1)
For i = 1 To Val(days)
    Set wsTemp = Sheets(1).Copy(After:=wsTemp)
    wsTemp.Name = mon & "." & (i)
Next i

Upvotes: 1

Related Questions