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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you record the number as text it will not drop any character.

Excel 2010
ABC
1length
2029387568Formated as text with ' in front of the number
3029387567Formated as number with formatting for leading zero

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
B2=LEN(A2)
B3=LEN(A3)

<tbody>
</tbody>

<tbody>
</tbody>
 
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
Nice!

One more request.. Can you make it skip ="000000000" ?

I do not want "0" nor "000000000".
 
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,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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