Closed Thread
Results 1 to 2 of 2

Macro to find the closest date and return the cell.address (inferior date)

  1. #1
    Registered User
    Join Date
    10-22-2020
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    7

    Macro to find the closest date and return the cell.address (inferior date)

    Hi everybody!

    Second post here, i think i need some help..

    I have a sheet that many users use to create TASK for vehicles. Those task should be created in order of "Starting date of the task".

    I've been able to find and create the task template under a task with the SAME date, i can't find a way to select the closest inferior date…

    Here's the code i use to find the SAME date:

    Dim findDate As Date
    Dim findStr As String
    Dim R As Range, WS As Worksheet

    Set findDate = TxtDateDebut 'This is from a TextBox in a UserForm
    Set WS = Worksheets("TĀCHES")

    findStr = Format(TxtDateDebut, "DD/MM/YYYY")

    MsgBox TxtDateDebut

    With WS

    Set R = .Cells.Find(what:=findStr, LookIn:=xlValues, lookat:=xlWhole, SearchDirection:=xlPrevious)

    If Not R Is Nothing Then

    ActiveSheet.Range(R.Address).Select
    ActiveCell.Offset(1, 0).Resize(AddTemplate.TxtNombre.Value + 3).EntireRow.Insert


    End With

    Tāches.png

    Let's say a user create a task that would start the 29/10/2020, i need to create that task in between the task that start the 28/10/2020 and the one that start the 02/11/2020.

    Anybody has an idea to get the immediate inferior date (if the exact one doesn't exist) ?

    Set R = .Cells.Find(what:=(<=)findStr, LookIn:=xlValues, lookat:=xlWhole, SearchDirection:=xlPrevious)

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,884

    Re: Macro to find the closest date and return the cell.address (inferior date)

    Administrative Note:

    Welcome to the forum.

    Unfortunately, this is a duplicate thread, and you are allowed only ONE thread per issue here.

    Please see Forum Rule #5 about thread duplication.

    I am closing this thread, but you may continue here in the original thread
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find closest week ending date to any date
    By jmont in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-25-2019, 09:41 AM
  2. Return value to a weekday closest to certain date
    By Ashleytaylor1702 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-10-2018, 05:24 PM
  3. VBA to loop through range to find date closest to today's date
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2017, 02:08 AM
  4. Lookup Given Date in Cell A1 to date list in Cell E:E and find closest match
    By Branbran10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2015, 03:26 PM
  5. Find cell with the last closest date
    By Chiefsotos in forum Excel General
    Replies: 8
    Last Post: 04-13-2014, 04:09 PM
  6. [SOLVED] look-up a date in a range and find the date that is closest todays date
    By VanShark in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-12-2014, 09:46 PM
  7. Find the closest zero to the left and return its address
    By mz8l18 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-03-2013, 04:43 PM

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