Guzzlr
Well-known Member
- Joined
- Apr 20, 2009
- Messages
- 982
- Office Version
- 2021
- Platform
- Windows
Code:
Option Explicit
Function StripChar(Txt As String) As String
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\D"
StripChar = .Replace(Txt, "")
End With
End Function
Sub PullNumbers()
Range("E2").Select
ActiveCell.Formula = "=StripChar(A2)"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E8"), Type:=xlFillDefault
Range("E2:E8").Select
Range("A1").Select
End Sub
So I'm using the above code to pull numbers from a text string that has numbers mixed in with it.
The problem is if I have a decimal place. The code will still pull the numbers to the right of the decimal and this I do not want.
For example, if I have:
[TABLE="width: 201"]
<tbody>[TR]
[TD="class: xl63, width: 201"]ahrihpxf9c / 1d.123
the code will pull back: 91123
But I only want 91
How can I trunc this number, or use the =LEFT...or something?
Thanks for the help[/TD]
[/TR]
</tbody>[/TABLE]