[英]Look at number (x) in a cell and copy the row (x) times
所以我有這個 excel 電子表格,我需要拆分其中包含多個項目的某些組,因為它們將單獨處理。
這是一個示例表:
詳細解釋需要發生的事情:
如果代碼運行正常,結果應該如下:
當我嘗試這樣做時出現的問題是我最終在我剛剛添加的行上運行我的代碼,並且我 go 進入無限循環。 提前感謝您的幫助!
編輯:我的代碼:
Sub Splitter()
Dim i As Integer
Dim j As Integer
For i = 2 To 63
If IsNumeric(Cells(i, 14).Value) And (Cells(i, 14).Value) > 1 Then
If Cells(i, 3).Value = Cells(i - 1, 3).Value And Cells(i, 4).Value = Cells(i - 1, 4).Value Then
Else:
Cells(i + 1, 2).Select
Range(Cells(i + 1, 2), Cells(62, 15)).Copy
ActiveCell.Offset(Cells(i, 14).Value, 0).Range("A1").Select
ActiveSheet.Paste
Range(Cells(i, 2), Cells(i, 15)).Copy
For j = 1 To Cells(i, 14).Value
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Next j
End If
End If
Next i
End Sub
根據我上面得到的評論,我想出了這個解決方案來稍微優化代碼。 對於我需要做的事情,似乎工作得很好。 我希望這可以幫助其他有類似斗爭的人。
Sub Splitter()
Dim i As Integer
Dim j As Integer
For i = 62 To 2 Step -1
If IsNumeric(Cells(i, 14).Value) And (Cells(i, 14).Value) > 1 Then
Range("C" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(0, 10).Range("A1").Select
Range(Cells(i + 1, 2), ActiveCell).Copy
Cells(i + 1, 2).Select
ActiveCell.Offset(Cells(i, 14).Value - 1, 0).Range("A1").Select
ActiveSheet.Paste
Range(Cells(i, 2), Cells(i, 13)).Copy
Cells(i, 2).Select
For j = 1 To (Cells(i, 14).Value - 1)
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Next j
End If
Next i
Application.CutCopyMode = False
Cells(1, 1).Select
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.