重新排列列中的数据

时间:2015-10-09 18:09:12

标签: excel google-sheets datasheet

有没有办法自动排列这些数据

enter image description here

进入这个

enter image description here

使用excel / google sheet / etc。基本上我有一个巨大的文件列表(第二列),我需要映射到它的相应文件夹(第一列ID)。

我需要的是将A列数据复制下来,但只复制到下面的空白单元格,然后再次为新文件夹ID复制,依此类推。

1 个答案:

答案 0 :(得分:1)

我碰巧有一个宏,提示用户向下复制数据的列。请参阅下文(注意您可能需要根据需要进行调整):

Sub GEN_USE_Copy_Data_Down()
Dim screenRefresh$, runAgain$
Dim lastRow&, newLastRow&
Dim c       As Range
Dim LastRowCounter$
Dim columnArray() As String

screenRefresh = MsgBox("Turn OFF screen updating while macro runs?", vbYesNo)
If screenRefresh = vbYes Then
    Application.ScreenUpdating = False
Else
    Application.ScreenUpdating = True
End If


Dim EffectiveDateCol As Integer
LastRowCounter = InputBox("What column has the most data (this info will be used to find the last used row")

CopyAgain:
With ActiveSheet
    lastRow = .UsedRange.Rows.Count
End With


' THIS WILL ASK THE USER TO SELECT THE COLUMN TO COPY DATA DOWN
MsgBox ("Now, you will choose a column, and that column's data will be pasted in the range" & vbCrLf & "below the current cell, to the next full cell")
Dim Column2Copy As String
Column2Copy = InputBox("What columns (A,B,C, etc.) would you like to copy the data of?  Use SPACES, to separate columns")
columnArray() = Split(Column2Copy)

Dim startCell As Range


For i = LBound(columnArray) To UBound(columnArray)
    Debug.Print i
    Column2Copy = columnArray(i)

    Set startCell = Cells(1, Column2Copy).End(xlDown)
    Do While startCell.row < lastRow
        If startCell.End(xlDown).Offset(-1, 0).row > lastRow Then
            newLastRow = lastRow
        Else
            newLastRow = startCell.End(xlDown).Offset(-1, 0).row
        End If
        Set CopyFrom = startCell
        Range(Cells(startCell.row, Column2Copy), Cells(newLastRow, Column2Copy)).Value = CopyFrom.Value
        Set startCell = startCell.End(xlDown)
    Loop
Next i

If screenRefresh = vbYes Then
    Application.ScreenUpdating = True
Else
    Application.ScreenUpdating = True
End If


End Sub

我刚才写过它,所以它可能会删除/组合行,但它应该可以工作(假设你试图只是将数据复制到A列)。