+ Reply to Thread
Results 1 to 3 of 3

Delete weekends sub started falling over!

Hybrid View

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Delete weekends sub started falling over!

    Hi All,

    The following code has been running absolutely fine for quite some time, then this morning it fell over with no apparent changes.
    Can anyone help?

    It seems to be falling over on the line "End If"

    Thanks in advance


    Sub DeleteSatSun()
    
    Sheets("PROCESS").Activate
    
    Dim currentrow As Long
    Dim usedrows As range
    On Error GoTo abort
    
    Set usedrows = ActiveSheet.UsedRange.rows
    For currentrow = usedrows.rows.count To 1 Step -1
    If Int(Application.WorksheetFunction.Weekday(usedrows.rows(currentrow).Columns("A:A"))) Mod 7 < 2 Then
    usedrows.rows(currentrow).EntireRow.Delete
    
    End If
    
    Next currentrow
    
    abort:
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Delete weekends sub started falling over!

    The code seems to work well, but try to change row:
    Set usedrows = ActiveSheet.UsedRange.Rows
    in
    Set usedrows = ThisWorkbook.ActiveSheet.UsedRange.Rows
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Re: Delete weekends sub started falling over!

    Aha, thanks Antonio,

    That seems to have stabilised it!

    Regards, Tim

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1