PDA

View Full Version : Convert Excel formula to VBA code



jujuaurich
04-28-2023, 11:48 AM
Hello,


In the factory where I work, we use the "Julian Day" calendar to list our batches.


By Excel I got the formula below that when I write the date 12/01/2023 (were we use day, month and year) it returns me the year and the letter "V" (that is necessary for our process) and the referent date of the "Julian Day" calendar



=TEXT(B3;"aa")& TEXT(B3; "V")&TEXT(B3- DATE( YEAR(B3);1;0); "000")


Thus, 12/01/2023 = 23V043


But I would need to apply this formula inside the userform, according to the attached file.


Can someone help me?

30768

Paul_Hossler
04-28-2023, 12:43 PM
When I enter 12/1/2023 or 1/12/2023 (d/m/y or m/d/y) I don't get 23V043

30769



Option Explicit
'=TEXT(B3;"aa")& TEXT(B3; "V")&TEXT(B3- DATE( YEAR(B3);1;0); "000")

Private Sub Inserir_Click()
Dim d As Date
Dim s As String
Dim jd As Long
d = CDate(Tbbatatidas.Text)
jd = d - DateSerial(Year(d), 1, 0)
Tbproducao.Text = Right(Year(d), 2) & Format(jd, "V000")
End Sub