Trong bài đăng này, tôi sẽ chỉ cho bạn cách chuyển đổi số peso thành chữ trong Microsoft Excel. Nó rất hữu ích khi sử dụng mẫu sổ làm việc Microsoft Excel để in séc. Chúng tôi sẽ hướng dẫn bạn cách sử dụng công thức hàm SpellNumber trong Microsoft Excel. Do đó, bất kỳ số tiền nào bằng tiền tệ Peso đều cho phép bạn chuyển đổi thành các từ tiếng Anh
Để chuyển đổi số tiền Đô la thành chữ, vui lòng truy cập bài viết này của Microsoft, nhấp vào đây
Công thức SpellNumber trong Excel là gì?
Hàm SpellNumber là công thức dùng để chuyển số thành chữ tiếng Anh trong Microsoft Excel. Để thêm khả năng này, bạn cần dán mã chức năng SpellNumber vào mô-đun VBA [Visual Basic for Applications] và lưu dưới dạng Sổ làm việc đã bật Excel Macro
Sau đây là hướng dẫn cách tạo hàm SpellNumber
Tạo hàm SpellNumber
BƯỚC 1. Mở Sổ làm việc Microsoft Excel của bạn. Trong một ô trống, hãy nhập số tiền hoặc số peso bạn muốn chuyển đổi. Sau này bạn phải gõ vào ô trống công thức =SpellNumber[D8] để có kết quả. Trong đó D8 là vị trí ô của số peso
Như mẫu trên mình có cung cấp P150. 45 thì nó phải được chuyển thành Một Trăm Năm Mươi Peso & 45/100 bằng cách sử dụng công thức =SpellNumber
BƯỚC 2. Nhấn phím Alt + F11 để mở cửa sổ trực quan cơ bản. Nhấp vào tab Chèn, sau đó nhấp vào thư mục Mô-đun trong Dự án VBA. Sao chép mã bên dưới, sau đó Dán vào mô-đun trống
Đánh dấu và sao chép mã bên dưới hoặc tải xuống tệp văn bản này
Tải xuống tệp SpellNumber txt
Option Explicit
'Main Function
Function SpellNumber[ByVal MyNumber]
Dim Pesos, Cents, Temp
Dim DecimalPlace, Count
ReDim Place[9] As String
Place[2] = " Thousand "
Place[3] = " Million "
Place[4] = " Billion "
Place[5] = " Trillion "
' String representation of amount.
MyNumber = Trim[Str[MyNumber]]
' Position of decimal place 0 if none.
DecimalPlace = InStr[MyNumber, "."]
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens2[Left[Mid[MyNumber, DecimalPlace + 1] & _
"00", 2]]
MyNumber = Trim[Left[MyNumber, DecimalPlace - 1]]
End If
Count = 1
Do While MyNumber ""
Temp = GetHundreds[Right[MyNumber, 3]]
If Temp "" Then Pesos = Temp & Place[Count] & Pesos
If Len[MyNumber] > 3 Then
MyNumber = Left[MyNumber, Len[MyNumber] - 3]
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Pesos
Case ""
Pesos = "No Pesos"
Case "One"
Pesos = "One Peso"
Case Else
Pesos = Pesos & ""
End Select
Select Case Cents
Case ""
Cents = " Pesos Only "
Case "One"
Cents = " and One Cent"
Case Else
Cents = " & " & Cents & "/100 Pesos Only"
End Select
SpellNumber = Pesos & Cents
End Function
' Converts a number from 100-999 into text
Function GetHundreds[ByVal MyNumber]
Dim Result As String
If Val[MyNumber] = 0 Then Exit Function
MyNumber = Right["000" & MyNumber, 3]
' Convert the hundreds place.
If Mid[MyNumber, 1, 1] "0" Then
Result = GetDigit[Mid[MyNumber, 1, 1]] & " Hundred "
End If
' Convert the tens and ones place.
If Mid[MyNumber, 2, 1] "0" Then
Result = Result & GetTens[Mid[MyNumber, 2]]
Else
Result = Result & GetDigit[Mid[MyNumber, 3]]
End If
GetHundreds = Result
End Function
' Converts a number from 10 to 99 into text.
Function GetTens[TensText]
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val[Left[TensText, 1]] = 1 Then ' If value between 10-19...
Select Case Val[TensText]
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val[Left[TensText, 1]]
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit _
[Right[TensText, 1]] ' Retrieve ones place.
End If
GetTens = Result
End Function
' Converts a number from 1 to 9 into text.
Function GetDigit[Digit]
Select Case Val[Digit]
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function
' Converts a number from 10 to 99 into text.
Function GetTens2[TensText]
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val[Left[TensText, 1]] = 1 Then ' If value between 10-19...
Select Case Val[TensText]
Case 10: Result = "10"
Case 11: Result = "11"
Case 12: Result = "12"
Case 13: Result = "13"
Case 14: Result = "14"
Case 15: Result = "15"
Case 16: Result = "16"
Case 17: Result = "17"
Case 18: Result = "18"
Case 19: Result = "19"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val[Left[TensText, 1]]
Case 2: Result = "2"
Case 3: Result = "3"
Case 4: Result = "4"
Case 5: Result = "5"
Case 6: Result = "6"
Case 7: Result = "7"
Case 8: Result = "8"
Case 9: Result = "9"
Case Else
End Select
Result = Result & GetDigit2 _
[Right[TensText, 1]] ' Retrieve ones place.
End If
GetTens2 = Result
End Function
' Converts a number from 1 to 9 into text.
Function GetDigit2[Digit]
Select Case Val[Digit]
Case 0: GetDigit2 = "0"
Case 1: GetDigit2 = "1"
Case 2: GetDigit2 = "2"
Case 3: GetDigit2 = "3"
Case 4: GetDigit2 = "4"
Case 5: GetDigit2 = "5"
Case 6: GetDigit2 = "6"
Case 7: GetDigit2 = "7"
Case 8: GetDigit2 = "8"
Case 9: GetDigit2 = "9"
Case Else: GetDigit2 = ""
End Select
End Function
BƯỚC 3. Nhấn Alt + Q để đóng, sau đó lưu tài liệu của bạn dưới dạng Sổ làm việc đã bật Excel Macro
BƯỚC 4. Mở lại sổ làm việc Microsoft Excel của bạn. Hãy thử sử dụng công thức =SpellNumber[Cell Reference] và nhấn enter. Ví dụ: =SpellNumber[D8] trong đó D8 là ô chứa số bạn muốn chuyển đổi. Bạn cũng có thể nhập số theo cách thủ công, chẳng hạn như =SpellNumber[150. 45]. Nó sẽ chuyển đổi số Peso sang từ tiếng Anh
Hướng dẫn này được thực hiện bằng phiên bản Microsoft Excel 2019
Vậy là xong, bạn đã hoàn thành. Nếu có thắc mắc về cách chuyển số peso sang chữ trong Excel, vui lòng để lại bình luận bên dưới