我急切地寻求有关我的 VBA 代码的帮助。我的问题非常详细和具体,因此我决定将其作为代码中的注释。如果这样的行为使我的问题变得模糊或模糊,请让我知道。简而言之,我的代码创建了一行(来自“FSR”工作簿),它满足了标准并将其粘贴到特定的工作表和特定的行中(由“FSR”工作表中的“P”和“Q”列的值给出)。我需要更多的是插入单元格(并将现有单元格向下移动)到我的代码粘贴复制单元格的相同位置,但在将它们粘贴到那里之前。我需要将单元格插入 A:J 列和工作表(“FSR”)中“G”列中的值给出的行中。我需要将这个新代码放入 FOR 循环,因为这个插入,以及复制和粘贴需要循环。现在在评论中添加问题代码:
Sub FromSOF()
Dim Worksheet As Worksheets
startrow = Worksheets("GUTS").Cells(10, 1)
endrow = Worksheets("GUTS").Cells(11, 1)
For x = startrow To endrow
If Cells(x, "O").Value = "P" Then
Worksheets(Cells(x, "P").Value).Select 'And here is the porblem. This one and three consecutive lines are to insert cells and shift the existing cells down. The cells need to be inserted into the worksheet given by the value in column "P" in Worksheet("FSR") and into the row given by the column "Q" in Worksheet("FSR")
Range("A" & Worksheet("FSR").Cells(x, "P").Value, "J" & Worksheet("FSR").Cells(x, "P").Value).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Worksheets("FSR").Select
Range("E" & x, "H" & x).Copy
Worksheets(Cells(x, "P").Value).Cells(Cells(x, "Q").Value, "C").PasteSpecial xlPasteAll
End If
Next
End Sub
谢谢大家!我希望我与代码的斗争将结束,因为您的礼貌与最诚挚的问候 Artur Rutkowski