+ Reply to Thread
Results 1 to 2 of 2

Thread: VBA transposing lines into rows but keep formating

  1. #1
    Registered User
    Join Date
    10-17-2011
    Location
    Austin
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA transposing lines into rows but keep formating

    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?

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010
    Posts
    856

    Re: VBA transposing lines into rows but keep formating

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0