I have a list of isbn numbers for books, with each cell being a different book, but some cells have multiple isbn's. I found/replaced all the spaces and commas with carriage returns, so the isbns each have their own lines.
I found some code, below, that splits the cells contents at the CR, and copies it to the B column, but some of the isbn's start with "0" and when it transposes the isbn over it formats it as a number, removing the 0 up front. How do I transpose the multi-line cells to a new column, split by rows, but most importantly keeping the numbers as text formating to leave the "0"?
Sub Lines2Rows()
Dim rList As Range, rCell As Range
Dim lRow As Long, vLines As Variant
Set rList = Range("A2", Range("A" & Rows.Count).End(xlUp)) ' list
lRow = 2
For Each rCell In rList
If rCell <> "" Then
vLines = Split(rCell, vbLf)
Range("B" & lRow).Resize(1 + UBound(vLines)).Value = Application.Transpose(vLines)
lRow = lRow + UBound(vLines) + 1
End If
Next rCell
End Sub
*or is there a short macro that I could use that would find all strings of numbers that arent 10 characters long and add 0's at the beginning to make it to 10 char?
Welcome to the forum. Please read the rules for surrounding your code with CODE tags. In the meantime, the formula below will take care of it for you.
Assuming values in the A column, put the following formula in your spreadsheet. Copy/paste special/values for the results where the original values in the A column are.
=IF(LEN(A1)<10,REPT("0",10-LEN(A1))&A1,A1)
If your question has been satisfactorily addressed, please consider marking it solved. Click here to see how.
Also, you might want to add to the user's reputation by clicking the scales icon - it's why we do what we do...
Thomas Lafferty
Analyst/Programmer
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks