我试图在excel工作表中找到一个代码来创建宏,该宏将从名为“Panel”和列"C“的工作表中复制值(从C3、C4等开始),并粘贴到称为"Pack”的工作表中,但按特定顺序:第一个单元格是A10,然后跳过B10,然后粘贴到C10,跳过D10,粘贴到E10,跳过F10,粘贴到G10,跳过H10,粘贴到I10,跳过J10,然后移动到下一行"11“,其顺序与跳过和粘贴的顺序相同。
此excel工作表的目标是“面板”工作表包含所有需要制造的项目列表,而"Pack“工作表将有一个要发货的相同项目的列表。然后,运算符将检查“跳过”列中的标记正确项。
随附的是一个屏幕截图的“包”工作表上的例子,假想的项目。

发布于 2022-02-10 20:16:49
复制和转置带偏移
Option Explicit
Sub FillPack()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
' Source (read (copied) from)
Dim sws As Worksheet: Set sws = wb.Worksheets("Panels") ' Worksheet
Dim sfRow As Long: sfRow = 3 ' First Row
Dim slRow As Long ' Last Row
slRow = sws.Cells(sws.Rows.Count, "C").End(xlUp).Row
If slRow < sfRow Then Exit Sub ' no data
' Destination (written to)
Dim dws As Worksheet: Set dws = wb.Worksheets("Pack") ' Worksheet
Dim dfRow As Long: dfRow = 10 ' First Row
Dim dr As Long: dr = dfRow ' Current Row
Dim dfCol As Long: dfCol = 1 ' First Column
Dim dc As Long: dc = dfCol ' Current Column
Dim dlCol As Long: dlCol = 9 ' Last Column
Dim dlRow As Long ' Last Row (just to clear the previous data)
dlRow = dws.Cells(dws.Rows.Count, dfCol).End(xlUp).Row
If dlRow >= dfRow Then ' Clear previous data
dws.Range(dws.Cells(dfRow, dfCol), dws.Cells(dlRow, dlCol)).ClearContents
End If
Dim sr As Long ' Current Row
For sr = sfRow To slRow ' loop through cells of column 'C'
dws.Cells(dr, dc).Value = sws.Cells(sr, "C").Value ' copy value
If dc < dlCol Then
dc = dc + 2 ' every other column
Else
dr = dr + 1 ' when all columns are filled then next row...
dc = dfCol ' ... and start with first column
End If
Next sr
MsgBox "Pack filled.", vbInformation
End Subhttps://stackoverflow.com/questions/71070919
复制相似问题