Filter last 9 digits from a 16-digit number within a text

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!
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Excel's maximum number precision is 15 digits. So you need to use a string. Before this line:

c.Value = e

put:

c.NumberFormat = "@"
 
Last edited:
Upvote 0
That is perfect, problem solved! Amazing, one simple line, couldn't find that anywhere, thank you!
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top