+ Reply to Thread
Results 1 to 2 of 2

To compare & find out the nearest date in the range with a common date

  1. #1
    Registered User
    Join Date
    06-10-2015
    Location
    Bengaluru, India
    MS-Off Ver
    2007
    Posts
    21

    To compare & find out the nearest date in the range with a common date

    Hello All,

    I just need a simple logic, I have a common date mentioned in the code and want to compare with the range of the dates in a column to find out the nearby dates . If the nearby dates are found the with respect to the common date it must be extracted and other dates are to ignored. The date in the column must be greater than the common date mentioned.

    Please Login or Register  to view this content.
    kindly anyone help me out, Thanks in advance

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: To compare & find out the nearest date in the range with a common date

    Hi,

    There are many ways to do what you want. The following are two sample methods:
    a. Using a range of values
    b. Using a loop
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    Lewis
    Last edited by LJMetzger; 12-04-2015 at 09:00 AM. Reason: Removed date_Range from the 'loop' example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Finding Nearest date in a range based on critera date
    By skate1991 in forum Excel General
    Replies: 5
    Last Post: 07-22-2015, 02:10 PM
  2. [SOLVED] find nearest last date from tody date
    By shoot for moon in forum Excel General
    Replies: 5
    Last Post: 07-18-2015, 06:25 PM
  3. [SOLVED] Find the Exact date, Nearest old and new date for the given input Letter) and date
    By thilag in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-17-2015, 05:13 AM
  4. Matching with a nearest date in a date range?
    By mrxlsx in forum Excel General
    Replies: 2
    Last Post: 05-05-2015, 01:23 PM
  5. Compare and find nearest date with criteria
    By Dwexdwex in forum Excel General
    Replies: 4
    Last Post: 08-18-2013, 09:51 AM
  6. Replies: 2
    Last Post: 01-04-2012, 09:15 AM
  7. How to find nearest date to that of given
    By TRJJK73 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2008, 06:30 PM

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