image

Excel不提供任何默认功能来转换印度卢比或任何货币的单词中的数字或金额。但这并不意味着我们不能将数字转换为印度卢比。我们可以创建一个自定义Excel公式,将数字转换为印度卢比的单词。我创建了这个自定义函数,可以将数字转换为印度卢比一词。您可以在下面下载宏文件。我已经在下面提到了代码并作了一些解释,以便您可以根据需要进行更改。

Excel函数可以将数字转换为印度卢比的单词,因此请使用此功能将任何10位以下的金额或数字转换为单词或卢比。我已将此函数命名为NUM_TO_IND_RUPEE_WORD。该函数的语法为:

=NUM_TO_IND_RUPEE_WORD(number)

您可以下载正在工作的宏文件:

`link:/wp-content-uploads-2020-03-Number-to-Words-indian-rupee.xls [Number to Words印度卢比]

现在,下面将提到该函数的代码。

该代码分为四个单独的功能。主要功能是NUM_TO_IND_RUPEE_WORD。其他三个函数Ge​​tHunderds(),GetTens()和GetDigits是帮助函数,它们帮助主函数形成字符串。

Function NUM_TO_IND_RUPEE_WORD(ByVal MyNumber, Optional incRupees As Boolean = True)

Dim Crores, Lakhs, Rupees, Paise, Temp

Dim DecimalPlace As Long, Count As Long

Dim myLakhs, myCrores

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 Paise and set MyNumber to Rupees amount.

If DecimalPlace > 0 Then

Paise = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))

MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

End If

myCrores = MyNumber \ 10000000

myLakhs = (MyNumber - myCrores * 10000000) \ 100000

MyNumber = MyNumber - myCrores  10000000 - myLakhs  100000

Count = 1

Do While myCrores <> ""

Temp = GetHundreds(Right(myCrores, 3))

If Temp <> "" Then Crores = Temp & Place(Count) & Crores

If Len(myCrores) > 3 Then

myCrores = Left(myCrores, Len(myCrores) - 3)

Else

myCrores = ""

End If

Count = Count + 1

Loop

Count = 1

Do While myLakhs <> ""

Temp = GetHundreds(Right(myLakhs, 3))

If Temp <> "" Then Lakhs = Temp & Place(Count) & Lakhs

If Len(myLakhs) > 3 Then

myLakhs = Left(myLakhs, Len(myLakhs) - 3)

Else

myLakhs = ""

End If

Count = Count + 1

Loop

Count = 1

Do While MyNumber <> ""

Temp = GetHundreds(Right(MyNumber, 3))

If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees

If Len(MyNumber) > 3 Then

MyNumber = Left(MyNumber, Len(MyNumber) - 3)

Else

MyNumber = ""

End If

Count = Count + 1

Loop

Select Case Crores

Case "": Crores = ""

Case "One": Crores = " One Crore "

Case Else: Crores = Crores & " Crores "

End Select

Select Case Lakhs

Case "": Lakhs = ""

Case "One": Lakhs = " One Lakh "

Case Else: Lakhs = Lakhs & " Lakhs "

End Select

Select Case Rupees

Case "": Rupees = "Zero "

Case "One": Rupees = "One "

Case Else:

Rupees = Rupees

End Select

Select Case Paise

Case "": Paise = " and Paise Zero Only "

Case "One": Paise = " and Paise One Only "

Case Else: Paise = " and Paise " & Paise & " Only "

End Select

'creating the string of words to translate number into words

NUM_TO_IND_RUPEE_WORD = IIf(incRupees, "Rupees ", "") & Crores & _ Lakhs & Rupees & Paise

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

该函数的代码很长,但易于理解。

要使用此代码,请在VBE中插入一个模块,然后复制粘贴。该功能可以直接在纸张上使用。它将数字转换成单词,特别是印度卢比格式。

好的,这就是您可以在Excel中使用自定义函数将数字转换为单词的方式。我希望这是有帮助的。如果您对本文或其他功能有任何疑问,请在下面的评论部分中提问。

相关文章:

Excel公式中的数组 ** |数组是每种技术语言中相同类型的集合值。在excel中,它与其他编程语言相同,但处理方式略有不同。链接:/ vba-user-defined-function [如何通过VBA创建用户定义的函数] * |了解如何在Excel中创建用户定义的函数。

在Microsoft Excel中使用VBA在另一个工作簿中使用用户定义的功能(UDF) **在另一个Excel工作簿中使用用户定义的函数。

在Microsoft Excel中使用VBA从用户定义的函数中返回错误值 **了解如何从用户定义的函数返回错误值。

热门文章:

`链接:/ keyboard-formula-shortcuts-50-excel-shortcuts可提高您的生产率[50 Excel快捷方式以提高生产率]更快地完成任务。这50个快捷键将使您在Excel上的工作速度更快。

link:/ vlookup-functions / formulas-and-functions-introduction- [如何使用Excel VLOOKUP函数]|这是excel中最常用和最受欢迎的功能之一,用于从不同范围和工作表中查找值。

link:/ tips-countif-in-microsoft-excel [如何使用]

link:/ vlookup函数的公式和函数介绍[Excel]

link:/ tips-countif-in-microsoft-excel [COUNTIF函数]|使用此惊人的功能对条件进行计数。

您无需过滤数据即可计算特定值。 Countif功能对于准备仪表板至关重要。

链接:/ excel-formula-and-function-excel-sumif-function [如何在Excel中使用SUMIF函数]这是仪表板的另一个重要功能。这可以帮助您汇总特定条件下的值。