按指定数量列出
我只需要一个简单的解决scheme,将数据中的数据移出每行指定的列数。
例如:
shift 2 xxxx 4 xxx 5 xxxx
所以2的前2列是空的,数据被移动到4的单元格3前4列是空的,数据被移出到单元格5。
从…开始:
运行这个:
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
会产生:
这对我有用
Sub test() Dim ws As Worksheet Dim rng As range Dim cell As range Set ws = ThisWorkbook.Worksheets(1) Set rng = range("A1", ws.range("A1").End(xlDown)) For Each cell In rng Dim i As Integer For i = 1 To cell.Value cell.Insert xlShiftToRight Next i Next cell End Sub
这应该适合你
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