vba
vba
' Purpose: Returns the last word from the given cell.
CountWord = Count
End Function
Function NumberToWords(ByVal MyNumber)
Dim Units As String
Dim Tens As String
Dim Hundreds As String
Dim DecimalPlace As Integer, Count As Integer
Dim Temp As String
Dim DecimalPart As String
MyNumber = Trim(CStr(MyNumber))
DecimalPlace = InStr(MyNumber, ".")
If DecimalPlace > 0 Then
DecimalPart = Mid(MyNumber, DecimalPlace + 1)
MyNumber = Left(MyNumber, DecimalPlace - 1)
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Units = Temp & Place(Count) & Units
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
NumberToWords = Application.Trim(Units) & " Dollars and " & DecimalPart & "
Cents"
End Function
GetHundreds = result
End Function
Function GetTens(TensText)
Dim result As String
result = ""
If Val(Left(TensText, 1)) = 1 Then
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
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))
End If
GetTens = result
End Function
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
Function MaxUnique(rng As Range) As Double
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
MaxUnique = WorksheetFunction.Max(dict.items)
End Function
Function FirstNonEmpty(rng As Range) As Variant
Dim cell As Range
For Each cell In rng
If cell.Value <> "" Then
FirstNonEmpty = cell.Value
Exit Function
End If
Next cell
FirstNonEmpty = "All empty"
End Function
Function ListDuplicatesWithCounts(rng As Range) As String
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
ListDuplicatesWithCounts = duplicates
End Function
ListDuplicates = duplicates
End Function
Function SumByColor(rng As Range, colorCell As Range) As Double
Dim cell As Range
Dim total As Double
Dim targetColor As Long
total = 0
SumByColor = total
End Function
Function LookupAllValues(lookupValue As String, lookupRange As Range, returnRange
As Range) As String
Dim i As Long
Dim cellValue As String
Dim result As String
Dim regex As Object
' Check if the lookup value is found in the cleaned cell value
If regex.Test(cellValue) Then
' If found, concatenate the corresponding value from the return range
result = result & Trim(returnRange.Cells(i, 1).Value) & ", "
End If
Next i
' Remove the trailing comma and space if results were found
If Len(result) > 0 Then
result = Left(result, Len(result) - 2)
Else
result = "Not Found"
End If
LookupAllValues = result
End Function
For i = 0 To Len(s1)
d(i, 0) = i
Next i
For j = 0 To Len(s2)
d(0, j) = j
Next j
For i = 1 To Len(s1)
For j = 1 To Len(s2)
If Mid(s1, i, 1) = Mid(s2, j, 1) Then
cost = 0
Else
cost = 1
End If
d(i, j) = Application.Min(d(i - 1, j) + 1, _
d(i, j - 1) + 1, _
d(i - 1, j - 1) + cost)
Next j
Next i
' Prompt user for the desired percentage only if it has not been set yet
If IsEmpty(similarityThreshold) Then
similarityThreshold = Application.InputBox("Enter the desired similarity
percentage (0-100):", "Similarity Percentage", 80, Type:=1)
' Remove the trailing comma and space if results were found
If matchCount > 0 Then
result = Left(result, Len(result) - 2)
Else
result = "Not Found"
End If
FuzzyLookup = result
End Function
txt = cell.Value
For i = 1 To Len(txt)
Dim currentChar As String
currentChar = Mid(txt, i, 1)
SeparateWordsAndNumbers = result
End Function
For i = 1 To coll.Count
arr(i - 1) = coll(i)
Next i
CollectionToArray = arr
End Function
' Trim leading and trailing spaces and replace multiple spaces with a single
space
CleanAndSpaceString = Trim(Replace(cleanedString, " ", " "))
End Function
' Remove the last comma and space if matches are found
If Len(result) > 0 Then
result = Left(result, Len(result) - 2)
Else
result = "No Match Found"
End If