# Finding # of years between 2 dates

#### Iceberg

##### Board Regular
Hello!

I am trying to write a bit of code to find the number of years between 2 columns of dates. I have one set of dates in Column D, another in E, and I would like the results to post in Column G.

Here's what I tried:

Rich (BB code):
``````For I = 2 To J
Let Range("G" & I).Value = Range("E" & I).Value - Range("D" & I).Value
Next I``````

It works, but it gives me the number of days instead of the number of years.

### Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

#### Jonmo1

##### MrExcel MVP
Try this

Rich (BB code):
``````For I = 2 To J
Let Range("G" & I).Value = Year(Range("E" & I).Value) - Year(Range("D" & I).Value)
Next I``````

Hope this helps.

#### Iceberg

##### Board Regular
Works like a charm! Thanks for your help!

#### eblake

##### Active Member
Try this:

Code:
``````For I = 2 To J
If Year(Range("E" & I).Value) > Year(Range("D" & I).Value) Then
Range("G" & I).Value = Year(Range("E" & I).Value) - Year(Range("D" & I).Value)
Else
Range("G" & I).Value = Year(Range("D" & I).Value) - Year(Range("E" & I).Value)
End If
Next I``````

Replies
3
Views
386
Replies
1
Views
323
Replies
5
Views
524
Replies
2
Views
303
Replies
3
Views
656

1,191,196
Messages
5,985,227
Members
439,950
Latest member
Xearo96

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back