Add the correct two digit year (Julian Year) in Column G depending on the year in Column E.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, Thanks to Mr. Rick Rothstein from this site, I have a VBA that will provide the current year. It will insert a 20 in front of the the last three days of the Julian Year in Columns G and E. However, my purpose is to subtract G from E to get the total days in Column I. Since Column E will never be in the past, we need to concern ourselves with Column G. Quite simply if G is greater than E then I need to have something written in the code so Column G is less than Column E. For example Column E has a value of 355 and Column G has a value of 027, the code will put a 20 in front of 355 for 20355. I need the code to recognize that a 21 needs to be added in front of 027 for 21027. Only the year will be adjust by one if necessary. Later in the year it would be fine until we get to the end of next year. I think it definitely need an "Else" statement in there someplace. I provide an image as well as my current VBA. Thank you,

VBA Code:
Sub Full_Julian_Date()
With Range("G2", Range("G" & Rows.Count).End(xlUp))
.Value = Evaluate(Replace("IF(LEN(@)=3,TEXT(NOW(),""yy"")&@,@)", "@", .Address))
With Range("E2", Range("E" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace("IF(LEN(@)=3,TEXT(NOW(),""yy"")&@,@)", "@", .Address))
  End With
  End With
End Sub

Date.JPG
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Greetings, Thanks to Mr. Rick Rothstein from this site, I have a VBA that will provide the current year. It will insert a 20 in front of the the last three days of the Julian Year in Columns G and E. However, my purpose is to subtract G from E to get the total days in Column I. Since Column E will never be in the past, we need to concern ourselves with Column G. Quite simply if G is greater than E then I need to have something written in the code so Column G is less than Column E. For example Column E has a value of 355 and Column G has a value of 027, the code will put a 20 in front of 355 for 20355. I need the code to recognize that a 21 needs to be added in front of 027 for 21027. Only the year will be adjust by one if necessary. Later in the year it would be fine until we get to the end of next year. I think it definitely need an "Else" statement in there someplace. I provide an image as well as my current VBA. Thank you,

VBA Code:
Sub Full_Julian_Date()
With Range("G2", Range("G" & Rows.Count).End(xlUp))
.Value = Evaluate(Replace("IF(LEN(@)=3,TEXT(NOW(),""yy"")&@,@)", "@", .Address))
With Range("E2", Range("E" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace("IF(LEN(@)=3,TEXT(NOW(),""yy"")&@,@)", "@", .Address))
  End With
  End With
End Sub

View attachment 28803
***UPDATE*** I made a mistake in the written form of my example. I meant to state" For example Column E has a value of 027 and Column G has a value of 355, the code will put a 20 in front of 355 for 20355. I need the code to recognize that a 21 needs to be added in front of 027 for 21027. " Thank you,
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top