lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I am trying to understand the code below. I have 2 questions now
1) What is the idea of using Mid() function
2) What does & mean.
souce:
https://www.automateexcel.com/vba/extract-number-from-string/[/COLOR][/COLOR]
I am trying to understand the code below. I have 2 questions now
1) What is the idea of using Mid() function
2) What does & mean.
Rich (BB code):
Temp=Temp&Mid(Phrase,Current_Pos,1)
Rich (BB code):
Function Extract_Number_from_Text(Phrase As String) As Double
Dim Length_of_String As Integer
Dim Current_Pos As Integer
Dim Temp As String
Length_of_String = Len(Phrase)
Temp = ""
For Current_Pos = 1 To Length_of_String
If (Mid(Phrase, Current_Pos, 1) = "-") Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
If (Mid(Phrase, Current_Pos, 1) = ".") Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
If (IsNumeric(Mid(Phrase, Current_Pos, 1))) = True Then
Temp = Temp & Mid(Phrase, Current_Pos, 1)
End If
Next Current_Pos
If Len(Temp) = 0 Then
Extract_Number_from_Text = 0
Else
Extract_Number_from_Text = CDbl(Temp)
End If
End Function
souce:
https://www.automateexcel.com/vba/extract-number-from-string/[/COLOR][/COLOR]
Last edited: