我遇到了问题,就像这个
0 500 100 1.8
500 800 50 1.6
800 2300 125 3.2
*我想要这种格式(将数字拆分成时间块格式),如下所示:*
00:00 05:00 -50 1800
00:00 05:00 -50 1800
05:00 08:00 -50 1600
08:00 23:00 -50 3200
08:00 23:00 -50 3200
08:00 23:00 -25 3200
,代码如下:
Option Explicit
Sub main()
Dim data As Variant
Dim iData As Long, datum As Long, iRow As Long
On Error Resume Next
With Range("A2", Cells(Rows.Count, 1).End(xlUp))
data = .Resize(, 4).Value
iData = LBound(data)
Do
datum = data(iData, UBound(data, 2) - 1)
Do While datum > 0
iRow = iRow + 1
.Cells(iRow).Resize(, 4) = Application.Index(data, iData, 0)
.Cells(iRow).Offset(, 3).Value = .Cells(iRow).Offset(, 3).Value * 1000
.Cells(iRow, UBound(data, 2) - 1).Value = -WorksheetFunction.Min(50, datum)
datum = datum - 50
Loop
iData = iData + 1
Loop While iData <= UBound(data)
.Resize(1, 4).Copy
.Resize(iRow, 4).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
End Sub
任何帮助都将不胜感激。