# Excel 2007 :: VBA Comparing Dates

May 30, 2012In functions it is easy to simply say =if(a1>b1, do X, don't do X)

But how do I do this in VBA? Excel 2007

In functions it is easy to simply say =if(a1>b1, do X, don't do X)

But how do I do this in VBA? Excel 2007

ADVERTISEMENT

How to compare two dates in excel. Like my requirement is I need to compare curent date vs from month begin date two weeks date.As of now I have tried like this.

Current Date : =TEXT(NOW(),"d")

Month Begindate : =TEXT(DATE(YEAR(NOW()),MONTH(NOW()),1)+14,"d")

And I have written condition like this : =IF(TEXT(NOW(),"d")

I have the following code which compares a string between two sheets. First sheet is 'data', second is 'saw'. I'm trying to copy an array of numbers (energy consumption for each hour of the day) based on machine ID and date (hence the compare string). How to modify it so it will copy the array of 24 number, not just the first number?

I have a few worksheets 'saw', drill, lathe. So I am using ActiveSheet, so I can run the same macro as all data is in the 'data' worksheet.

Sub test_copy()

Dim a, i As Long, txt As String

a = Sheets("data").Range("a1").CurrentRegion.Value

With CreateObject("Scripting.Dictionary")

.CompareMode = 1

[Code] .......

--------------------

datasheet below

--------------------

Excel 2007

A

B

C

D

E

F

G

H

I

J

K

L

M

N

1

sawing machine

2

100569

01/10/2012

0.1

0.25

0.89

0.25

0.22

0.14

0.56

0.47

0.58

0.45

0.47

[Code] .......

-----------------------

machine sheet

-----------------------

Excel 2007

A

B

C

1

100569

23/09/2010

2

100569

24/09/2010

[Code] ...........

I have two tables each containing a column with Account ID. I want to in table A put a column that will return a yes or value of 1 if the ID in that row shows up in the ID column in table B. I have windows 7 with excel 2007

View 1 Replies View RelatedI am in strange situation where I have a data with Invoice Dates. These dates are in Text. However, when I convert it into reall excel dates. For some reason the dates do not come right. convert my text dates into excel real dates. I did a lot of google search and apply these three methods but all of these gave me strange result I was not expecting. These are the methods I used and the result of each method.

Method 1 : Using Text to Column Wizard (Excel 2007)

I highlighted invoice column and went into text to column wizard. I clikced on Date button, and selected MDY format. Strangely enough, my result was day, month and year i.e. DMY which does not seem right.

Then I press Control ~ on this data as shown in second view.

Inv DateMDY09/22/1122/09/201108/31/1131/08/201108/31/1131/08/201108/31/1131/08/201108/31/1131/08/2011

control ~ (overview)

Inv DateMDY09/22/114080808/31/114078608/31/114078608/31/114078608/31/1140786

2nd Method - Using formula to convert text date to real dates When I used formula, I get the following result. As you can see, formula is converting text dates into different system dates than the first method.Further strange things is when I take these system dates i.e. 4283 and in 2007 excel format use "Short Date" the same system date gets converted into wrong year as shown in the second view.

Inv DateFormulaFormula Result09/22/11=DATE(MID(B2,7,2),MID(B2,1,2),MID(B2,4,2))428308/31/11=DATE(MID(B3,7,2),MID(B3,1,2),MID(B3,4,2))426108/31/11=DATE(MID(B4,7,2),MID(B4,1,2),MID(B4,4,2))426108/31/11=DATE(MID(B5,7,2),MID(B5,1,2),MID(B5,4,2))426108/31/11=DATE(MID(B6,7,2),MID(B6,1,2),MID(B6,4,2))426108/31/11=DATE(MID(B7,7,2),MID(B7,1,2),MID(B7,4,2))4261

2nd view - system dates are getting converted into 1911

Inv DateFormulaFormula Result09/22/11428322/09/191108/31/11426131/08/191108/31/11426131/08/191108/31/11426131/08/191108/31/11426131/08/191108/31/11426131/08/1911

Similarly, I tried other methods or copying blanks etch but none seems to convert text dates into real (system dates).

I have a Billing Data where i want to Calculate TAT between two dates in Excel 2007.. I received the Invoice from Vendors on specfic date but due to discrepances, i rejected the invoice, after few date i received a rectified Invoice from Vendor... so how can i calculate the TAT from 1st Receipt to Rejection..

Column A Column B Column C Column D Column E Column F

(Receipt Date) (Rejected Date) (Re-Receipt Date) (Rejected Date) (Final Receipt Date) (Formula for Finding

Rejection TAT)

E.g : In Column F, TAT to be calculated from 1st Receipt Date to Rejection Date, but if i received the rectified bill & after inputing the Re Receipt Date in Column C, then the Cell in Column F will remain blank, but again if it is rejected due to some error, & after mention the 2nd Rejection Date in Column D, then the TAT to be calculated from 1st receipt to 2nd Rejection (Column D), but if i received the Final Rectifed Invoice & after mentioning the Receipt Date in Column E, then the Cell in Column F will remain blank.. but pls note, if the invoice is not rejected the, the Cell in Column F will remain blank..

I have tried IF Forumula but in vain.. i can only nest 1st receipt to 1st rejection i.e : =IF(AB6= "", "",(TODAY()-AB6))

I am using Excel 2007 and am having some trouble formatting a column for dates. I am setting up a template spreadsheet for the company I work for. The template spreadsheet has a sheet for entering the raw data and a sheet for summarizing it. I need new dates that are to be entered to be formatted correctly. I have set up a sample spreadsheet and inputted some sample data which looks like the following:

Date

06.11.13

07.11.13

08.11.13

05.10.13

06.09.13

Now if I format these cells as English(UK) dates with the "dd.mm.yy" format the data>sort cannot sort these dates from oldest to newest. I can correctly sort them by using "text to columns" however if i do this then it only format's the cells that currently have a date entered into them and not any new date entries.

So in summary: Format cells into a date format does not allow dates to be sorted using the data>sort tool. (I assume that as they cannot be sorted ,a formula that searches for cells with dates before a certain date will not work either) Text to columns does not allow new entries to be formatted in the same way as the cells that had data in them when the text to columns tool was used.

Is there a way to format blank cells so that they will recognize the data inputted as a date?

I have a stripped down data source for debugging purposes. I only have 4 rows of data for test purposes. The dates are formatted as dates.

When I create the pivot table the dates become my column values. When I select the first date in the pivot table the Group By Field menu option is grayed out. I tried setting a tabular format but didn't work.

Can I use dates as argument in Boolean arithmetic? I have a list of name with their date of birth and I would like to tell who is between 18 and 25. It's easy enough with number but with dates? Excel 2007

View 9 Replies View RelatedI am setting up a Cattle management system in excel 2007. In the column F are the date of births for each individual animal. Example: F2 13/03/2013 F3 23/05/2013. I would then like to highlight the cells with the dates in to find all the cattle that are under the age of 16 months from the current date.

View 9 Replies View RelatedWhat I have done is entered code to auto generate the date in column O whenever data is entered or altered in column A. Here is that code:

VB:

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A:A")) Is Nothing Then _

Target.Offset(0, 14).Value = Now

End If

End Sub

What I am trying to do now, is create a column that will take the information from O and do a sort of COUNTIF function that will count how many items of data were entered on a certain date by the day. For a clearer example, I want it to tell me how many items were entered/altered on 7/23. But I also want it to continuously calculate it for each date after that. Preferably automatically, but if a macro is needed I can create an update button.

Once it can achieve that I would like to create a dynamic graph that will automatically (or via macro button) update to show the last 5 days. It should display the date and how many items were entered that day.

I am using Office 2007.

I have a column in my data set that consists of dates and times in this format: 2014/08/02 01:46:49 PM. I am trying to convert these dates and times to numbers so that I can actually use these values for calculations and regression analysis. When I click on one of the cells, I get a number that is revealed along with decimals. For example, the cell with 2014/08/02 01:46:49 PM had a stored value of 41853.574. I tried to highlight the entire column of dates + times and click on the format cells button. I selected the number category under number but that did not work. I also tried to use the =DateValue(Cell #) function but that did not allow for distinguishing between the same date but different times.

What are my options for converting these dates and times to numbers that I can work with? Is there a way to get the entire column of dates + times to show each cell's numeric stored value?

We are using Excel and Outlook 2007 and 2010 in our office and this program needs to work with both versions of each, Excel and Outlook. I need to have a csv file exported from outlook to identify locations of meetings and when they occur. I can do this manually but it could be used at multiple times by different people

View 4 Replies View RelatedI am working with the Ganntt chart and horizontal bar charts but can't seem to figure out a way to force the X-Axis to behave properly.

In Excel 2007, I am trying to get the X-Axis to show major units of Months. However, in my chart options I can only change the Y-Axis to be Date/Monthly.

Changing my data layout (from the below) to be a vertical format produces the same problem, just in the other direction.

My data looks as follows:

System

Blocker

Production

Migrataion

Retired

Sys1

1/1/2012

780

Sys2

1/1/2012

400

60

90

Sys3

2/1/2013

30

5

1

The Blocker column is formatted as "No Fill" in order to cover a portion of the time-scale.

My X-Axis displays as random dates throughout the period and all of my data displays properly in terms of the scale on the grid.

What is NOT working is that the dates shown on the X-Axis really need to be based on a Monthly scale instead of the randomly selected dates Excel is using.

20120823.xlsx

I can't seem to find the right combination of options to make that happen or force a scale on the X-Axis.

Excel 2007 Q: I have a combo box (ActivX) that I want to be able to choose a a date from a range of dates in column A on sheet 'Working Copy'. I want a cell to update with the number/position of the date when the date is chosen i.e. the first date in the range yields 1 the second date yields 2 and so on. I also want the date to be displayed in dd-mmm-yyyy format. I am able to get the cell to give the correct position of the date but the date reverts to five digit number in combo box. I can change the code to return the correct date in the combo box when the date is chosen but then the cell just returns 0.

How can I make it so that the combo box returns the correct date and the cell updates with the position instead of jsut one or the other?

Here is the code I am using

Private Sub ComboBox1_Change()

ComboBox1.Value = Format(ComboBox1.Text, "dd-mmm-yyyy")

End Sub

or

Private Sub ComboBox1_Change()

Sheets("Working Copy").Range("G1").Value = ComboBox1.ListIndex + 1

End Sub

I am trying to figure-out how to set up conditional formatting of dates in a column (e.g. Date Submitted) and have these dates, and/or cell, change color as time progresses. I have Excel 2007.

For instance I have an application submitted on 11/20/2011 in a cell. I would like to have the date change color (Yellow) after 30 days have passed.

Then do the same except change to Red after 60 days have passed the date.

I searched the forums and did not find this particular problem. I of course may have missed it too...

My guess was to try "$A$1

Excel 2007 I have a spreadsheet of file boxes the keeps a log of boxes, contents, locations and shred dates. Currently figuring out when and which boxes can be shredded is a manual hunt, find, and then deal with it. I can use CF and Sorting but I have been looking at some search type functions to return a list meeting the requirements and trying to step my way towards that.

1st attempt. Was find out how many boxes meet the shred (before today) that have not already been detroyed. Column K is the Shred Date, D1 is Todays date, Column G is Status. Got this working good.

[QUOTE]]=SUMPRODUCT(--(Log!K2:K2136(lessthan)STATS!D1)*SIGN(LEN(Log!K2:K2136)))-(COUNTIF(Log!G2:G2136,"Destroyed"))[/QUOTE

My failed attempt came at trying to find the earliest shred date excluding those that have been destroyed. This is not really neeed but I was hoping it would get me closer to creating the list of boxes that meet shred that have not already been destroyed.

Note: Column A is the Box No. and the spreadsheet contains blanks as we continue to add file boxes to storage.

Below array formula find the highest box number used by each department.

Code:

=A4&"-"&TEXT(MAX(IF(Log!$A$2:$A$2136"",(LEFT(Log!$A$2:$A$2136,LEN(A4))=A4)*RIGHT(Log!$A$2:$A$2136,3))),"000")

I would like to create a list of boxes including Column A "Box no.", Column H "Location", Column K "Shred Date" for any box whose shred date is before today that has not aleady been labeled "Destroyed" in Column G.

I am using excel 2007, and trying to incorporate a VLookup into some code. The VLookup is comparing dates, which I think may be part of the problem.

View 3 Replies View RelatedFormula for comparing two dates

Cell A1 = 5/5/2012 (Recent Date)

Cell B1 = 5/6/2011 (Hire Date)

Cell C1 = =YEAR(A1)-YEAR(B1)

This formula gives a result of '1' even though it doesn't show an entire year.

I've also tried this formula:

=DATEDIF(B1,A1, "y")

This is more accurate as it formulates '0' as the result.

However if for some reason the 'Recent Date' in cell A1 is 5/5/12 and the 'Hire Date' in cell B1 is after the 'Recent Date', say 5/6/2012, the formula =YEAR(A1)-YEAR(B1) has a result of '0' and the formula =DATEDIF(B1,A1, "y") has a result of #NUM!.

Is there a formula that will give me accurate results whether the 'Hire Date' is before or after the 'Recent Date'? Maybe something similar to =DATEDIF(B1,A1, "y") but will give a result of '0' instead of #NUM!

I have a comments field in a reporting SS that I need to flag when the last comment is over a week old. The date however is entered into the same cell as the comment and the latest comment is put on a new line in the same cell, ie:

13/02 - Jimmy met with Shirley to discuss project A

10/02 - awaiting meeting

07/02 - agenda issued

Now, if needed I can make the date complete to include the year, ie 13/02/2008.

Is it possible using functions to see if the date in this cell is over 7 days previous to the date in another cell, say J1?

I tried =IF(LEFT(H10,10)

I have trouble trying to get the right sintax of comparing two dates locates in two different sheets.

Example:

Sheet 1, cell A1 = 12/11/2009

Sheet 2, cell B1 = 12/11/2009

If I need to do something based on condition that Sheet1 date = sheet 2 date, how will the code be written? I have

If Sheets("Sheet1").range("A1") = Sheets("Sheet2").range("B1") Then

**** my code here

I'm trying to determine if one date meets the criteria to be considered 'on time'. I have two columns: estimated completion date and completion date. I want to compare the completion date to the estimated completion date and if completion date is <= completion date but is NOT = 1/1/2099 then I met my date. I've tried this several different ways and problem is I cannot make it work.

When estimated completion date is 1/1/2099 'on time' should be 'no'

When estimated completion date is not 1/1/2099 but is greater than completion date 'on time' should be 'no'

When completion date is <= estimated completion date and estimated completion date is not equal to 1/1/2099 'on time' should be 'yes'

And I have a null date to deal with also but if I can satisfy the first 3 criteria I can manipulate the null values manually.

I have a problem regarding month formatting

I have 12 columns, Jan 2013 - Dec 2013.

I need to set a format in which if I enter a num eg 15 on the Jan Column, format comes as "15-Jan" format

or If i type 20 on the march column , it comes as "20-Mar" format

I would need it in Date format, because I would be comparing dates later on.

I’m attempting to find values that are within a band of .001 of the values of cells in columns L through O and searching columns B through I for values that meet the .001 criteria and copying the values to columns Q, R, S, and T respectively.

I mentioned the values in L, M, N and O are where the comparisons will be made and these values are tagged to a specific date in Column K. I need to find the dates in Column A that are in between the values of K and the cell beneath it. For example, in K4 I have a date of 10/3/99 and the next date I have in K5 is 10/5/99. I would then query Column A for the dates 10/06/99 (A4), 10/07/99 (A5), and 10/08/99 (A6). The values I need to find within the .001 band are in Columns B through I (B4:I6). Lastly, when reach the last value in Column K, query all values in Column A greater than last value in K and copy the appropriate values in B through I to Q through T.

Rules for copying data to Column Q, R, S, and T:

For Column Q-

Find values in B, C, or D that’s within plus or minus .001 of M and copy the value of B, C, or D into Column Q of the same row.

For Column R-.................

Any easy formula to compare two columens of fixed dates and count how many of each fall within a certain range of each other.

So, for example:

Col 1 Col 2

20/1/11 21/1/11

20/1/11 31/1/11

18/1/11 24/1/11

Lets say col one is a start date and col 2 is an end date. Now say I want to count the number of times the end date falls within8 days of the start

I would have thought that something as simple as

Code:

sumproduct(--(a1:a3<(b1:b3+8))

would work, but clearly I am making a fundamental error, and no matter what I try I'm getting stuck.

I want to be able to compare a user-input date to dates in a column, and return 1 if the date in the column is less than the user input date, and 2 if it is greater.

Code:

Dim TheString As String, ReportDate As Date

TheString = InputBox("Please enter the date this report was run in mm/dd/yyyy format:", "What date do you want to enter?", "mm/dd/yyyy")

If IsDate(TheString) Then

ReportDate = DateValue(TheString)

[Code] ...

Code:

ActiveCell.FormulaR1C1 = _

"=IF(R[-1]C[23]

I have a simple formula to compare dates but it isn't working. I am missing something obvious. Any help is appreciated:

IF(BB64=Current_Date,"Today","Previous"))

where

Current_Date = today()

BB64 = an array that is a feed from a streaming quote company: =ILX|Q!'f,Date' .

When I format this cell it looks exactly like Current_Date, but is displays "Previous". Somehow it is not doing an apples to apples comparison even though the values lookthe same.

I need to compare dates that include both the date and time of day, to find when the day changes.

I have a large list of dates (also includes the time of day in the same cell). There are specific values in the next column that correspond to that date. Some of the values that are too great and have to be changed. This I have figured out with some help from this forum. When a value is changed I need to add together all the values for the corresponding day, some could be above and some could be below.

I'm trying to make a simple chart, which maps the value of an investment fund over time. I wanted to use the new 'Table' feature within Excel 2010 to format and maintain the formulae within the Table, and the 'Header' for the table contains the date, which is not at regular intervals.

If I opt not to use the Table feature, I can create a line-chart with ease, and Excel recognises that the Dates are indeed dates and plots the graph correctly. The minute I convert over to a Table, the Date headers are no longer recognised as dates, and are instead plotted as if they were text, at regular intervals.

I've tried multiplying the Date Headers by 1 to force them back to true Dates, but this still does not work. I've also changed the setting on the horizontal axis to Date axis rather than automatic, but still no joy.

I have currently browsed the forums and have came up with a code to compare two columns from two separate excel books and then highlight anything matching with the CompareRange. Here is a few more details about the problem:

- I have two excel sheets. And data like this in each sheet:

(First Sheet) (Second Sheet)

-A B N O

-7 .7 3 .56

-6 .6 8 .45

-5 .5 9 .55

-4 .4 11 .2

-3 .3 8 .22

-2 .2 9 .55

-1 .1 8 .54

As you can see, given this example nothing should be highlighted once the macro is run since nothing from Column A or B from the first sheet matches directly with Column N & O from the second sheet. The problem is that with the macro (module) I have come up with will highlight "3" from Column A and ".2" from Column B, just because they appear in Column N & Column O respectivally. What I want: I only want a number to be highlighted if both the numbers "7" & ".7" are matched in the same row of Column N & Column O on the other spreadsheet. To be a little more precise, I'll give an example. Say I edited the data to be like this.

(First Sheet) (Second Sheet)

A B N O

7 .7 3 .56

8 .45 8 .45

5 .5 9 .55

11 .4 11 .2

3 .3 8 .22

2 .2 9 .55

1 .1 8 .54

With this data, I would want the second row of A & B ("8" & ".45") highlighted, while my error "3" of Column A and ".2" of Column B is not highlighted. Also, I would like it if row 4 of Column A & B ("11" & ".4") is not highlighted at all either, just because in O it is .2 and in B it would be .4 even though the 11's match. Attached is the macro/module I have entered in which is working kind of correctly but producing the mistake. And also, (kind of a lesser problem), both the files with data will have the same header, example would be if Column A & Column N both had "Dogs" as it's title in Row 1 and Column B & O both had "Cats" as it's title in Row 1. Is there anyway the macro can be adjusted so it compares those two columns between the two workbooks without me even having to select or assigning a range?

HTML Code:

Sub Find_Matches()

Dim Column1 As Range

Dim Column2 As Range

[Code]....

Copyrights 2005-15 www.BigResource.com, All rights reserved