按指定数量排列的列

时间:2016-06-30 12:59:16

标签: excel excel-vba vba

我只需要一个简单的解决方案,将数据移出每行中指定的列数。

例如:

shift                                   
2           x   x   x   x           
4                   x   x   x       
5                       x   x   x   x

因此,对于2,前两列为空,数据转移到单元格3 对于4,前4列为空,数据移出到单元格5。

3 个答案:

答案 0 :(得分:1)

这对我有用

AppInitialize

答案 1 :(得分:0)

从:

开始

enter image description here

运行此:

Sub Kolumator()
    Dim i As Long, N As Long
    Dim K As Long, j As Long

    N = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To N
        K = Cells(i, 1).Value
        Cells(i, 1).Clear
        For j = 1 To K - 1
            Cells(i, 1).Insert shift:=xlToRight
        Next j
    Next i
End Sub

将产生:

enter image description here

答案 2 :(得分:0)

这应该对你有用

Option Explicit

Sub MoveCells()

Dim cell As Range
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

For Each cell In ws.Range(Cells(1, 1), Cells(Cells.Rows.Count, "A").End(xlUp))
Range(Cells(cell.row, 2), Cells(cell.row, 2).End(xlToRight)).Cut Range(Cells(cell.row, 2), Cells(cell.row, 2).End(xlToRight)).Offset(0, cell.Value)
Next cell

End Sub