ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Identifying Weekends (https://www.excelbanter.com/excel-discussion-misc-queries/146547-identifying-weekends.html)

Jepane

Identifying Weekends
 
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


Dave Peterson

Identifying Weekends
 
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...

Jepane wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 10:53 PM.

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