EXCEL如何用VBA实现一列数据平均分成7列数据?
发布网友
发布时间:2022-11-25 06:49
我来回答
共3个回答
热心网友
时间:2023-10-09 00:10
给你代码吧。
Sub bb()
Dim iEndRow, iAve, j, i
iEndRow = Sheet1.[a65536].End(xlUp).Row
iAve = Fix(iEndRow / 7)
j = 1
For i = 1 To Sheet1.[a65536].End(xlUp).Row
If i Mod iAve = 0 Then
Sheet2.Cells(iAve, j).Value = Sheet1.Cells(i, 1).Value
j = j + 1
Else
Sheet2.Cells(i Mod iAve, j).Value = Sheet1.Cells(i, 1).Value
End If
Next
End Sub
热心网友
时间:2023-10-09 00:10
这样子试试吧,呵呵……
Sub 分列()
For i = 1 To 7000 Step 1000
Sheet1.Activate
Sheet1.Range(Cells(i, 1), Cells(i + 1000 - 1, 1)).Select
Selection.Copy
Sheets(2).Activate
Cells(1, (i + 1000) / 1000).Select
ActiveSheet.Paste
Next i
End Sub追问谢谢回复,不过,这提示缺少对象啊
热心网友
时间:2023-10-09 00:11
Sub cs()
arr = Sheet1.Range("A1").CurrentRegion.Resize(, 1)
r = UBound(arr)
ReDim brr(Int(r / 7), 6)
For i = 1 To r
brr(h, l) = arr(i, 1)
l = l + 1
If l = 7 Then h = h + 1: l = 0
Next
Sheet2.Range("A1").Resize(h + 1, 7) = brr
End Sub