例如,如果我有30行,並且我想複製第1,第2和第3,請跳過五,然後複製下三個,然後再跳過五,然後複製下面三行:How我可以這樣做嗎?到目前爲止,我只有這個公式複製excel中的第n行
=OFFSET(Sheet1!$A$1,(ROW()-1)*5,0)
只讓我一個單元格的值,但我想整個行復制到另一個工作表。
任何幫助將是偉大的!感謝
例如,如果我有30行,並且我想複製第1,第2和第3,請跳過五,然後複製下三個,然後再跳過五,然後複製下面三行:How我可以這樣做嗎?到目前爲止,我只有這個公式複製excel中的第n行
=OFFSET(Sheet1!$A$1,(ROW()-1)*5,0)
只讓我一個單元格的值,但我想整個行復制到另一個工作表。
任何幫助將是偉大的!感謝
Here is a hint:
Row Number Modulus 8 in (1,2,3) identifies the target Row Numbers.
Enter in first column, first row and copy down for each column:
=IF(AND(MOD(ROW(Sheet1!A1),8) > 0,MOD(ROW(Sheet1!A1),8) < 4),Sheet1!A1,"")
謝謝你的回答。我仍然想知道如何複製3行,跳過下一個第N行,複製3行,跳過下一個第n個數字等等。 – 2014-10-31 18:50:02
他暗示模數。將「= MOD(ROW(A1),8)」放入工作表的A1單元格中並向下拖動,看看會發生什麼。 – 2014-10-31 19:01:34
嘗試,
=OFFSET(Sheet1!$A$1,(ROW(1:1)-1)+INT((ROW(1:1)-1)/3)*5,COLUMN(A:A)-1)
填寫向右和向下是必要的。
VBA增加:
Sub copy_some()
Dim r As Long
With ActiveSheet.Cells(1, 1).CurrentRegion
For r = 1 To .Rows.Count Step 8
.Cells(r, 1).Resize(3, .Columns.Count).Copy _
Destination:=Sheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next r
End With
End Sub
這將這樣的伎倆。只需使用Cells(row#,Col#)作爲循環。
Sub Copy3Skip5()
Dim iRow As Integer
Dim count As Integer
Dim tRow As Integer
Dim lastRow As Integer
Dim source As String
Dim target As String
source = "Sheet1"
target = "Sheet2"
'Get the last row on your source sheet.
lastRow = Sheets(source).Range("A65536").End(xlUp).Row
'Set the Target Sheet first row
tRow = 2
'assuming your data starts on Row 2 after a header row.
'Loop through the Source sheet
For iRow = 2 To lastRow
count = 1
Do While count <= 3
'Cells(tRow, 1) translates to Range("A2") if tRow = 2 and "A3" if tRow = 3. and so on
Sheets(target).Cells(tRow, 1) = Sheets(source).Cells(iRow, 1)
tRow = tRow + 1
iRow = iRow + 1
count = count + 1
Loop
'add 4 to the iRow, because we already added 1 at the end of the previous loop
iRow = iRow + 4
Next iRow
End Sub
你的問題被標記[VBA] - 你是如何使用公式? – pnuts 2014-10-31 18:21:33
對不起,我沒有指定,我願意使用VBA或公式。我也使用excel 2003.這個公式被放到表2中並拖放。它收集所需列中的每個第5個值。不過,我希望複製整個行。 – 2014-10-31 18:24:24
不適合所有要求,但是你可以考慮在Sheet1中添加一個'= MOD(ROW() - 1,8)'的列,並將其過濾爲<3並複製仍然可見的內容。 – pnuts 2014-10-31 19:04:26