Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Delete non weekdays

On Fri, 7 Dec 2007 02:28:02 -0800, Arne Hegefors
wrote:

Hi! I have long lists of dates that I often have to clean by deleting all
dates that are weekend dates. I am trying to write a sub that does this for
me (i know how to do it in a worksheet but it takes too long time since i
have very many books..). I tried selction the dates that I want to clean and
then running the macro but that obviously does not work. Is it posiible to do
this in any way? any help appreciated!

Sub deleteWeekEnds()
Dim i As Integer
i = Weekday(Selection, vbMonday)
If i = 6 Or i = 7 Then
Selection.Row.Delete
End If
End Sub


What you need to do is select the bottom row in your range, and then step
upwards, testing and deleting as you go.

I'm not sure what the most efficient way in your worksheet is to select the
bottom row, so I just used column A, but you can change this in many ways.

Here's an example:

=======================================
Option Explicit
Sub DelWeekends()
Dim LastRow As Range, c As Range
Dim i As Long
'you should change this to reflect the appropriate column
Set LastRow = Range("a65535").End(xlUp)

For i = LastRow.Row To 1 Step -1
Set c = Cells(i, 1)
If IsDate(c) Then
If Weekday(c) = vbSaturday Or Weekday(c) = vbSunday Then
c.EntireRow.Delete
End If
End If
Next i
End Sub
====================================
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weekdays Kerryn Excel Discussion (Misc queries) 7 July 5th 08 01:56 AM
Weekdays Arne Hegefors Excel Programming 5 October 26th 07 10:10 AM
Weekdays only! rexmann Excel Discussion (Misc queries) 2 August 14th 07 02:52 PM
just weekdays peter the swede Excel Programming 9 September 4th 06 09:51 PM
Weekdays Jeff Excel Discussion (Misc queries) 7 February 15th 05 12:18 AM


All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"