vba编码以重新排列数据集
我有几个数据范围集,每7x12个单元格一次,都按列排列,所以我想把它重新排列成行。 某些范围集可能为空,因此我将忽略该范围集。附图显示了当前结果和所需结果。非常感谢。 示例图像:vba编码以重新排列数据集,vba,excel,Vba,Excel,我有几个数据范围集,每7x12个单元格一次,都按列排列,所以我想把它重新排列成行。 某些范围集可能为空,因此我将忽略该范围集。附图显示了当前结果和所需结果。非常感谢。 示例图像: 您可以尝试一下。请查看专栏并更新您的场景 Public Sub DataRearrange() Dim LastRowInSet As Long, LastCol As Long, LastRowInTransposedData As Long, ColumnIncrease As Long Dim j
您可以尝试一下。请查看专栏并更新您的场景
Public Sub DataRearrange()
Dim LastRowInSet As Long, LastCol As Long, LastRowInTransposedData As Long, ColumnIncrease As Long
Dim j As Long
' Change this to the width of your repeating data set
ColumnIncrease = 4
' Change this to your relevant Sheet Name
With Sheets("InsertYoursheetNameHere")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
' There's no point doing it if there's only one set so lets Exit
If LastCol <= ColumnIncrease Then Exit Sub
For j = ColumnIncrease + 1 To LastCol Step ColumnIncrease
LastRowInSet = .Cells(.Rows.Count, j).End(xlUp).Row
LastRowInTransposedData = .Cells(.Rows.Count, 1).End(xlUp).Row
Range(.Cells(LastRowInTransposedData + 1, 1), .Cells(LastRowInTransposedData + LastRowInSet, ColumnIncrease)).Value2 = Range(.Cells(1, j), .Cells(LastRowInSet, j + ColumnIncrease - 1)).Value2
Range(.Cells(1, j), .Cells(LastRowInSet, j + ColumnIncrease - 1)).Clear
Next j
End With
End Sub
你的帖子只包含要求,没有你方面的特别努力来表明你试图解决这个问题。为了让我们能够帮助您,您需要展示到目前为止您在代码示例中所做的工作,以及您遇到的问题,特别是代码引发异常。。。。请看一下入门指南。您说您的数据是每7x12个,但在示例输出中,它是每4x5个。是哪一个?非常感谢,我已经解决了这个问题,现在我有另一个问题。我想复制第29个单元格,从C2开始,在K5之前粘贴它们,间距相同,本例为29。我的编码如下:子副本Dim lngRow As Long:lngRow=1 Dim lngLoop As Long:lngLoop=29直到IsEmptyCellslngLoop,1 CellslngLoop,1.Copy CellslngRow,K3 lngLoop=lngLoop+29 lngRow=lngRow+29 Loop End SUB如果这解决了您的问题,请将其标记为接受答案,并在其左侧打勾。恐怕你需要为你的另一个问题开始一个新问题