Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:54:10+00:00 2026-06-02T21:54:10+00:00

Following on from this question, Defining a range from values in another range ,

  • 0

Following on from this question, Defining a range from values in another range, (thanks Siddharth!) I want to edit the code to list the the tasks in order by most amount of days to shortest. Had a brief comment chat with Siddharth where he suggested the best way would be to create a temp sheet containing the data, sort that by arrived data and create the message box, before deleting the temp sheet. Any ideas where to start? Can I export the msg string to a new sheet or does it need to be a variable other t to be stored in a sheet

Option Explicit

Sub Notify()
    Dim WS1 As Worksheet
    Dim Chk As Range, FltrdRange As Range, aCell As Range
    Dim ChkLRow As Long
    Dim msg As String
On Error GoTo WhatWentWrong

Application.ScreenUpdating = False

Set WS1 = Sheets("Ongoing")

With WS1
    ChkLRow = .Range("C" & Rows.Count).End(xlUp).Row

    '~~> Set your relevant range here
    Set Chk = .Range("A1:K" & ChkLRow)

    '~~> Remove any filters
    ActiveSheet.AutoFilterMode = False

    With Chk
        '~~> Filter,
        .AutoFilter Field:=3, Criteria1:="NO"
        '~~> Offset(to exclude headers)
        Set FltrdRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
        '~~> Remove any filters
        ActiveSheet.AutoFilterMode = False

        For Each aCell In FltrdRange
            If aCell.Column = 8 And _
            Len(Trim(.Range("B" & aCell.Row).Value)) <> 0 And _
            Len(Trim(aCell.Value)) <> 0 Then
                msg = msg & vbNewLine & _
                      "Request for contractor code " & .Range("B" & aCell.Row).Value & _
                      " dispensing month " & .Range("A" & aCell.Row).Value & _
                      " has been in the cupboard for " & _
                      DateDiff("d", aCell.Value, Date) & " days."
            End If
        Next
    End With
End With

'~~> Show message
MsgBox msg
Reenter:
Application.ScreenUpdating = True
Exit Sub
WhatWentWrong:
MsgBox Err.Description
Resume Reenter
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:54:12+00:00Added an answer on June 2, 2026 at 9:54 pm

    Is this what you are trying?

    Option Explicit
    
    Sub Notify()
        Dim WS1 As Worksheet, TmpSht As Worksheet
        Dim Chk As Range, FltrdRange As Range, aCell As Range
        Dim ChkLRow As Long, TSLastRow As Long, i As Long
        Dim msg As String
    
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets("Alistair_Weir").Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
    
        On Error GoTo WhatWentWrong
    
        Application.ScreenUpdating = False
    
        Set WS1 = Sheets("Ongoing")
    
        With WS1
            ChkLRow = .Range("C" & Rows.Count).End(xlUp).Row
    
            '~~> Set your relevant range here
            Set Chk = .Range("A1:K" & ChkLRow)
    
            '~~> Remove any filters
            ActiveSheet.AutoFilterMode = False
    
            With Chk
                '~~> Filter,
                .AutoFilter Field:=3, Criteria1:="NO"
                '~~> Offset(to exclude headers)
                Set FltrdRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
                '~~> Remove any filters
                ActiveSheet.AutoFilterMode = False
    
                '~~> Add Temp Sheet
                Set TmpSht = Sheets.Add
                ActiveSheet.Name = "Alistair_Weir"
    
                '~~> Copy required rows to temp sheet
                TSLastRow = 1
                For Each aCell In FltrdRange
                    If aCell.Column = 8 And _
                    Len(Trim(.Range("B" & aCell.Row).Value)) <> 0 And _
                    Len(Trim(aCell.Value)) <> 0 Then
                        WS1.Rows(aCell.Row).Copy TmpSht.Rows(TSLastRow)
                        TSLastRow = TSLastRow + 1
                    End If
                Next
            End With
        End With
    
        With TmpSht
            '~~> Sort Data
            .Columns("A:H").Sort Key1:=.Range("H1"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    
            '~~> Create the message
            For i = 1 To TSLastRow - 1
    
                msg = msg & vbNewLine & _
                      "Request for contractor code " & .Range("B" & i).Value & _
                      " dispensing month " & .Range("A" & i).Value & _
                      " has been in the cupboard for " & _
                      DateDiff("d", .Range("H" & i).Value, Date) & " days."
            Next
    
            '~~> Delete the temp sheet
            Application.DisplayAlerts = False
            .Delete
            Application.DisplayAlerts = True
        End With
    
        '~~> Show message
        MsgBox msg
    Reenter:
        Application.ScreenUpdating = True
        Exit Sub
    WhatWentWrong:
        MsgBox Err.Description
        Resume Reenter
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from this question , I now want to know how to stop
Following on from this question I now have code that can attach to a
So following on from this question: Erlang lists:index_of function? I have the following code
Following on from this question I am using the code provided in one of
Following on from this question , I am interested in finding out how you
following on from this question (Developing to an interface with TDD), I'm still having
Following on from this question...I'm trying to unit test the following scenario: I have
Following on from this question... What to do when you’ve really screwed up the
Following the CSS style trick from this question I was able to create a
Following this question, it seems that it is possible to open a file from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.