使用标题将单个单元格内容重新格式化为多个

时间:2016-02-16 20:09:34

标签: excel csv formatting

我从在线商店导出一个订单,将变量导出为.csv文件中的单个单元格。

tier: Elite | division: Male/Male Team | captain shirt size: Large | teammate shirt size: XLarge | Team Name: Terrible 2's | Participant/Volunteer Waiver & Liability Release   Captain's Full Name: Craig Carroll | Participant/Volunteer Waiver & Liability Release   Teammate's Full Name: Ashley Carroll | Waiver & Release of All Claims & Assumption of Risk   Captain's Intials: cc | Waiver & Release of All Claims & Assumption of Risk   Teammate's Initials: ac | Age Requirement: Yes

这是它导出到一个单元格的内容。有没有办法使单词前面的:成为标题,如在A1中,和文本在|之前成为A2的价值?我已经使用了text to columns功能,但它创建了格式为tier:Elite的单元格,依此类推。有关400个订单或订单项的解决方案的任何建议吗?

original

期望 ![expectation

等等

2 个答案:

答案 0 :(得分:2)

我建议采取以下步骤:

  • 使用|作为分隔符
  • 时提到的文字到列
  • 然后向下转置数据(突出显示行,复制,选择要粘贴的单元格然后编辑特殊转置)
  • 使用转置数据再次使用文本到列,这次使用:作为分隔符

数据最终会采用以下格式:

tier                 Elite 
division             Male/Male Team 
captain shirt size   Large 
teammate shirt size  XLarge 
Team Name            Terrible 2's
...

(仅显示前五行,因为其他行中有大量文字)

答案 1 :(得分:0)

此宏假设原始数据位于 Sheet1 A 列中。重组后的数据将放在 Sheet2

Sub ReOrganize()
    Dim N As Long, i As Long, K As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    K = 1

    For i = 1 To N
        ary = Split(Cells(i, "A").Value, "|")
        For Each a In ary
            bry = Split(a, ":")
            With Sheets("Sheet2")
                .Cells(K, 1).Value = bry(0)
                .Cells(K, 2).Value = bry(1)
                K = K + 1
            End With
        Next a
    Next i
End Sub

enter image description here