将多个Excel列分组为行


1

目前,我正在编写一个列有教师评论内容的专栏。

我想用内容中的单词之间的空格或逗号或标点符号来划分它。

同时,我想取出内容中的每个单词,然后将它们放入行而不是列。

例:

凯瑟琳是一个好女孩。 - >这是老师的评论。

在excel中划分后,我有“Catherine是一个好女孩。”在6列中,1列1个单词。

但是,我希望将单词的结果放入行中。它看起来像这样,有6行:

Catherine
is
a
good
girl
.

Answers:


2

Excel有能力做到这一点

  1. 将数据复制到一个或多个列或行中。

  2. 在粘贴复制的数据之前,右键单击第一个目标单元格(要将数据粘贴到其中的行或列的第一个单元格),然后单击“选择性粘贴”。

  3. 在“选择性粘贴”对话框中,选择“转置”,然后单击“确定”。

您将在对话框的右下角找到“切换”复选框:

在此输入图像描述

本文来自Excel 2003帮助,但该过程一直适用于最新的Excel。但是,对话框可能看起来不同。


将每个单词放入自己的变量后,如何将几行放入一列?abcdefghi到abcdefghi然而,这只是一个样本试用。我正在使用2000个值的大数据所以任何方式去做吗?谢谢
cody_q 2012年

?? 您可以选择整个当前的Excel工作表,选择复制,“插入”新工作表,然后“粘贴特殊” - 一次性转置所有当前工作。您不必一次做一行。
Bon Gart

0

以下VBA代码可以解决问题。

Sub FlattenToSingleCol()
    Cells(1, 1).Activate ' Go to the top left

    ' Go past the last row that starts with a word
    Do Until IsEmpty(ActiveCell)
        DoEvents
        ActiveCell.Offset(1).Select
    Loop

    ' Set curRow to the last row that starts with a word (the row above ActiveCell)
    curRow = ActiveCell.Row - 1

    Do While curRow > 0
        DoEvents
        Cells(curRow, 1).Activate

        ' Go right past the last cell that contains a word
        Do Until IsEmpty(ActiveCell)
            DoEvents
            ActiveCell.Offset(0, 1).Activate
        Loop

        ' Come back left to the last cell that contains a word
        If ActiveCell.Column > 1 Then
            ActiveCell.Offset(0, -1).Activate
        End If

        ' Insert a new row below the current one for each
        Do Until ActiveCell.Column = 1 ' Move each non-empty cell to a new row and move left to the edge
            DoEvents
            ActiveCell.Offset(1).EntireRow.Insert
            Cells(ActiveCell.Row + 1, 1).Value = ActiveCell.Value
            ActiveCell.Clear
            ActiveCell.Offset(0, -1).Select
        Loop

        ' Go to the row above. Processing from the bottom up avoids re-processing lines we just inserted below.
        curRow = ActiveCell.Row - 1
    Loop
End Sub
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.