Serial numbers and ZEROS

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
Hello,

I have a problem with disapearing zeros..

my formula so far to copy proper numbers to other sheet is:

Code:
Dim cellR As RangeDim lastRowR As Long, r As Long


lastRowR = Range("J" & Rows.Count).End(xlUp).row
r = 2


For Each cellR In Sheets(1).Range("J1:J" & lastRowR)
     If Len(cellR) = 9 Or Len(cellR) = 14 Then
        cellR.EntireRow.Copy Sheets("SERIAL").Cells(r, 1)
        r = r + 1
    End If
Next

the problem is that the files that I need to work on have values in column J looking like this:

="00000000"
="029384756"
="000776819"
="284758933"

I need to copy entire rows to my new sheet if value in column J has 9 or 14 characters. The formating makes things difficult.

we can strip those numbers of ="" but than excel is removing leading zeros.

Anybody know how to bypass this?


Best Regards
W.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If you record the number as text it will not drop any character.

Excel 2010[TABLE="class: grid, width: 500"]
<colgroup><col><col><col><col></colgroup><tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD]length[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: right"]02938756[/TD]
[TD="align: right"]8[/TD]
[TD]Formated as text with ' in front of the number[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: right"]02938756[/TD]
[TD="align: right"]7[/TD]
[TD]Formated as number with formatting for leading zero[/TD]
[/TR]
</tbody>[/TABLE]
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="class: grid, width: 100%"]
<tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TD="width: 10"]Cell[/TD]
[TD="align: left"]Formula[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B2[/TH]
[TD="align: left"]=LEN(A2)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B3[/TH]
[TD="align: left"]=LEN(A3)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Can you modify my VBA scrip from first post to auto-do the trick? the problem is that column J has every value like this =" ******** " - within the quotes and with equal sign..
 
Upvote 0
Try

Code:
Dim cellR As Range
Dim lastRowR As Long, r As Long

lastRowR = Range("J" & Rows.Count).End(xlUp).Row
For x = 2 To lastRowR
    Cells(x, "J") = "'" & Cells(x, "J")
Next x

r = 2
For Each cellR In Sheets(1).Range("J1:J" & lastRowR)
     If Len(cellR) = 9 Or Len(cellR) = 14 Then
        cellR.EntireRow.Copy Sheets("SERIAL").Cells(r, 1)
        r = r + 1
    End If
Next
 
Upvote 0
Try

Code:
Dim cellR As Range
Dim lastRowR As Long, r As Long

lastRowR = Range("J" & Rows.Count).End(xlUp).Row
For x = 2 To lastRowR
    
    Cells(x, "J") = "'" & Cells(x, "J")
Next x

r = 2
For Each cellR In Sheets(1).Range("J1:J" & lastRowR)
     If (Len(cellR) = 9 Or Len(cellR) = 14) And cellR <> 0 Then
        cellR.EntireRow.Copy Sheets("SERIAL").Cells(r, 1)
        r = r + 1
    End If
Next
 
Upvote 0
Hi Again!

Scott T, Your work is great!

I have another mod to do..

When my script i looking for numbers (nine or fourteen chars) ="123456789", sometimes there is an 10th, 11th / 15th, 16th char and it looks like this 123456789/P or 987654321/2 or 875639275/+. Can macro look for two last chars and accept them as correct even if its above 9 or 14 char when there is SLASH (/) at 10 or 15?

Best Regards
W.
 
Upvote 0
Does this do what you want?

Code:
Dim cellR As Range
Dim lastRowR As Long, r As Long
lastRowR = Range("J" & Rows.Count).End(xlUp).Row
For x = 2 To lastRowR
    
    Cells(x, "J") = "'" & Cells(x, "J")
Next x
r = 2
For Each cellR In Sheets(1).Range("J1:J" & lastRowR)
     If (Len(cellR) = 9 Or Len(cellR) = 14 Or Mid(cellR, 10, 1) = "/" Or Mid(cellR, 15, 1) = "/") And cellR <> 0 Then
        cellR.EntireRow.Copy Sheets("SERIAL").Cells(r, 1)
        r = r + 1
    End If
Next
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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