Page 1 of 1

แสดงค่าวันเป็นเลข 2 หลัก

Posted: Mon Jun 08, 2020 11:22 am
by waritthorn
ต้องการให้ VBA แสดงค่าของวันที่ในกรณีที่เป็นเลขเดี่ยวให้เติม 0 ด้านหน้า
มีสูตรที่สามารถแสดงวันที่เป็นเลข 2 หลักได้ไหมครับ โดยไม่ต้องเขียนเงื่อนไข If

Code: Select all

Function createcode(sname As String, mtype As String, _
                                d As Date) As String

    s = Left(UCase(sname), 2)
    m = Left(UCase(mtype), 1)
    
    createcode = s & m & "A" & Month(d) & Day(d)
    
End Function
โดยต้องการให้ผลที่ได้เป็นค่า XYZ0608 (วันที่8เดือน6)

Re: แสดงค่าวันเป็นเลข 2 หลัก

Posted: Mon Jun 08, 2020 7:17 pm
by snasui
:D ตัวอย่าง Code ครับ

createcode = s & m & "A" & Month(d) & Format(Day(d),"00")

Re: แสดงค่าวันเป็นเลข 2 หลัก

Posted: Tue Jun 09, 2020 9:58 am
by waritthorn
ขอบคุณมากครับอาจารย์