TOP

Funcția VBA: Format

Descriere

Funcția VBA Format returnează un șir cu o dată sau un număr în formatul specificat.


Sintaxă Format

Format(valoare, format_mask)

Exemplu VBA Format

Folosind funcția Format pentru a afișa valori numerice în diferite formate:

Sub FormatExample1()

     '98.1%
     MsgBox Format(0.9814, "0.0%")

     '54'321.90
     MsgBox Format(54321.9, "##'##0.00")

     '54 321.90 €
     MsgBox Format(54321.9, "# ##0.00 €")

End Sub

Folosind funcția Format pentru a afișa o dată în diferite formate:

Sub FormatExample2()
    
     myDate = #10/30/2020 3:35:45 PM#
    
     '30.10.20
     MsgBox Format(myDate, "dd/mm/yy")
    
     '30 October 2020
     MsgBox Format(myDate, "d mmmm yyyy")
    
     'Friday
     MsgBox Format(myDate, "dddd")
    
     '30/10/2020 15:35
     MsgBox Format(myDate, "dd/mm/yyyy hh:nn")
    
     'Friday 30 at 15h35
     MsgBox Format(myDate, "dddd d at h\hnn")

End Sub

Formate de date

Un tabel cu diferite formate de dată care poate fi utilizat cu funcția Format (de exemplu, pentru data 01-08-2021 09:05:07):

SimboluriExempluDescriere
d 8 Day (from 1 to 31)
dd 08 Day (from 01 to 31)
ddd Fri Day of the week (abbreviated)
ddddFridayDay of the week
m 1 Month (from 1 to 12)
mm 01 Month (from 01 to 12)
mmm January Month (abbreviated)
mmmmJanuaryMonth
yy 21 Year (last 2 digits)
yyyy2021 Year
h 9 Hours (from 0 to 23)
hh 09 Hours (from 00 to 23)
n 5 Minutes (from 0 to 59)
nn 05 Minutes (from 00 to 59)
s 7 Seconds (0 to 59)
ss 07 Seconds (00 to 59)

Meniul Utilitare YLC din LO Calc

Meniul Utilitare YLC din LO Calc

Meniul Utilitare YLC din Excel

Meniul Utilitare YLC din Excel