Unicam
New Member
- Joined
- Mar 22, 2006
- Messages
- 31
Hello,
I am trying to find a solution for what I think is a challenging problem. I have a large file with cells filled with text (converted from a database, imported into Excel).
The text is in rows of column A and always contains a 16 digit number, which is what I need. I am able to clean up this text and show only this number, but then Excel shows the last digit as a '0'.
An example of the text I need to filter the 16-digit number from:
GIRO 6838657 K MAHMODBETALINGSKENM. 7062542158461684 STORNOADMINISTRATIEVE REDEN 1 ZIE DE TOEGEZONDEN KENNISGEVINGVAN VERHAAL OF CJIC.NL/VZD
I've altered some of the information in here so this is fake. The text is messy but all I need is the number.
This is the macro I use to clean up the text and leave only the 16 digit number:
Sub CleanUp
Dim e As Variant
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\d{16}"
Columns(1).NumberFormat = String(16, "0")
For Each c In Range("A1", Cells(Rows.Count, "A").End(xlUp))
e = ""
On Error Resume Next
e = .Execute(c.Value)(0)
If e <> "" Then
c.Value = e
End If
Next c
End With
End Sub
It sort of works, but when I run it, I get this number as a result: 7062542158461680 (last digit is changed into a zero).
I've been trying to insert this line into the macro but it doesn't help:
Columns("A:A").NumberFormat = "@"
How do I change the outcome of this macro into the actual number?
If this is impossible to do, I can also manage if there is a way to filter only the last 9 digits from the 16 digit number. I can work with that, too.
I use Excel XP (2002) at work. Can anyone help me out?
Thanks in advance!
I am trying to find a solution for what I think is a challenging problem. I have a large file with cells filled with text (converted from a database, imported into Excel).
The text is in rows of column A and always contains a 16 digit number, which is what I need. I am able to clean up this text and show only this number, but then Excel shows the last digit as a '0'.
An example of the text I need to filter the 16-digit number from:
GIRO 6838657 K MAHMODBETALINGSKENM. 7062542158461684 STORNOADMINISTRATIEVE REDEN 1 ZIE DE TOEGEZONDEN KENNISGEVINGVAN VERHAAL OF CJIC.NL/VZD
I've altered some of the information in here so this is fake. The text is messy but all I need is the number.
This is the macro I use to clean up the text and leave only the 16 digit number:
Sub CleanUp
Dim e As Variant
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\d{16}"
Columns(1).NumberFormat = String(16, "0")
For Each c In Range("A1", Cells(Rows.Count, "A").End(xlUp))
e = ""
On Error Resume Next
e = .Execute(c.Value)(0)
If e <> "" Then
c.Value = e
End If
Next c
End With
End Sub
It sort of works, but when I run it, I get this number as a result: 7062542158461680 (last digit is changed into a zero).
I've been trying to insert this line into the macro but it doesn't help:
Columns("A:A").NumberFormat = "@"
How do I change the outcome of this macro into the actual number?
If this is impossible to do, I can also manage if there is a way to filter only the last 9 digits from the 16 digit number. I can work with that, too.
I use Excel XP (2002) at work. Can anyone help me out?
Thanks in advance!
Last edited: