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

Livin404

Active Member
Joined
Jan 7, 2019
Messages
392
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:

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Livin404

Active Member
Joined
Jan 7, 2019
Messages
392
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

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,
 

Watch MrExcel Video

Forum statistics

Threads
1,127,620
Messages
5,625,910
Members
416,141
Latest member
Bartek9q

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
Top