2013-07-26 94 views
0

我正在拼命尋找有關VBA代碼的幫助。我的問題非常詳細和特別,因此我決定將它作爲代碼中的評論。如果這樣的行爲讓我的問題變得模糊或模糊,請讓我知道。 簡而言之,我的代碼標出了一行(來自「FSR」工作簿),其滿足條件並將其粘貼到特定工作表和特定行(由「FSR」工作表中的值「P」和「Q」列給出)。我需要更多的是插入單元格(並將現有單元格向下移動)到我的代碼粘貼複製單元格的同一位置,但在將它們粘貼到那裏之前。我需要將單元格插入到A:J列中,並插入Worksheet(「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 

謝謝大家提前!下面 我希望我的代碼鬥爭將結束因你禮貌 枝條問候 阿圖爾·盧特考斯基

回答

0

代碼將創建一個和數據複製到:

'Create line 
Worksheets(Worksheets("FSR").Cells(x,"P").Value).Rows(Worksheets("FSR").Cells(x,"Q").Value).EntireRow.Insert 
'Copy data (without clipboard) 
Range("E" & x, "H" & x).Copy Worksheets(Worksheets("FSR").Cells(x,"P").Value).Cells(Worksheets("FSR").Cells(x,"Q").Value,1) 
相關問題