Consulting

Results 1 to 4 of 4

Thread: Reformat Spreadsheet

  1. #1
    VBAX Regular
    Joined
    Aug 2013
    Posts
    15
    Location

    Reformat Spreadsheet

    I have a spreadsheet that needs to be reformatted. The attached sample shows how the data came in columns A & B. Columns E through L show how it needs to be reformatted. Any assistance would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    below procedure will work for 5 consecutive rows of data of same structure for a single vendor no.
    so you should manually copy/paste Address2 and Phone values to columns I and L and delete their rows .

    i picked a cell value which is common to all records, "Short Name", to distinguish between records.


    below is the key to access each record's field info. that means i assume all fields of all records are in the same row order.
    BEN010 Benefits Brokers Exchange
    Short Name: Benefits B
    Address: 1800 St. James Place, Ste. 650
    Houston, TX
    77056


    Sub reorg()
    
    Const srcText As String = "Short Name"
    Dim fCell As Range
    Dim firstAddress As String
    Dim LastRow As Long
    
    With Worksheets("Sheet1")
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        Set fCell = .Range("A2:A" & LastRow).Find(srcText)
        If Not fCell Is Nothing Then
            firstAddress = fCell.Address
            Do
                .Range("D" & fCell.Row - 1).Value = fCell.Offset(-1, 0).Value
                .Range("E" & fCell.Row - 1).Value = fCell.Offset(-1, 1).Value
                .Range("F" & fCell.Row - 1).Value = fCell.Offset(0, 1).Value
                .Range("G" & fCell.Row - 1).Value = fCell.Offset(-1, 1).Value
                .Range("H" & fCell.Row - 1).Value = fCell.Offset(1, 1).Value
                .Range("J" & fCell.Row - 1).Value = fCell.Offset(2, 0).Value
                .Range("K" & fCell.Row - 1).Value = fCell.Offset(3, 0).Value
                Set fCell = .Range("A2:A" & LastRow).FindNext(fCell)
            Loop While Not fCell Is Nothing And fCell.Address <> firstAddress
        End If
    End With
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Aug 2013
    Posts
    15
    Location
    Thank you so much for the help! Greatly appreciated.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome. im glad it helped.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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