|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
附上代码- Sub 矩形1_Click()
- Dim arr()
- Dim Arr2()
- Dim Count As Integer
- Dim Count2 As Integer
- Count2 = 1
- arr = Range("A2:G" & Cells(Rows.Count, 1).End(xlUp).Row).Value
- For i = 1 To UBound(arr)
- Count = Count + Application.WorksheetFunction.RoundUp(arr(i, 4) / 10000, 0)
- Next
- ReDim Arr2(1 To Count, 1 To 7)
- For i = 1 To UBound(arr)
- If arr(i, 4) <= 10000 Then
- For j = 1 To 7
- Arr2(Count2, j) = arr(i, j)
- Next
- Count2 = Count2 + 1
- Else
- 余数 = arr(i, 4)
- For k = 1 To Application.WorksheetFunction.RoundUp(arr(i, 4) / 10000, 0)
- For j = 1 To 7
- Arr2(Count2, j) = arr(i, j)
- Next
- Arr2(Count2, 1) = arr(i, 1) & "_" & k
- Arr2(Count2, 4) = Application.WorksheetFunction.Min(余数, 10000)
- 余数 = 余数 - Application.WorksheetFunction.Min(余数, 10000)
- Count2 = Count2 + 1
- Next
- End If
- Next
- With Sheets.Add
- On Error Resume Next
- Application.DisplayAlerts = False
- Sheets("TEMP").Delete
- Application.DisplayAlerts = True
- .Name = "TEMP"
- .Range("A1").Resize(UBound(Arr2), 7) = Arr2
- .Columns.AutoFit
- End With
- End Sub
复制代码 |
|