Identifying Weekends

J

Jepane

Hi,
Im seeking some kind of help here

Ive got a range of dates given by DATE function (01-16-2007 01-17-2007
01-18-2007, etc.), i've also formated the cells so to get only the name of
the day (Mon-Tue-Wed, etc).

But Now Im trying to get a macro to identify Weekends so to get an action
done, lets say for example, to insert 3 rows after each Sunday.
Obviously i cant program something like : If range ("x") = "Sunday" then....
Since those are real dates.

Id appreciate any kind of help

Thanx in advance
Jepane
 
D

Dave Peterson

Option Explicit
Sub testme()
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long

With Worksheets("sheet1")
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
If Weekday(.Cells(iRow, "A").Value) = vbSunday Then
.Rows(iRow).Resize(3).Offset(1, 0).Insert
End If
Next iRow
End With
End Sub

If you're doing this to make the report look prettier, maybe just increasing the
rowheight would be better. You could increase the rowheight of the next row or
increase the rowheight of the Sunday row--and change it so that the vertical
alignment is at the Top.

Inserting rows into raw data can screw up other stuff--filters, charts,
pivottables...
 

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

Similar Threads

Date Formula Excluding Weekends 3
Summing rows based upon condition 2
add 4 days 9
CrossTab report "super" columns 5
Calculating occupational sick pay entitlement 0
vlookup help? 8
Skip weekends 1
Payroll 2

Top