小弟遇到列的複雜/刪除與匯入上的問題
詳述如下:
我需要將
1. Sheet1中有疑問的資料轉到sheet2中
2. 將Sheet1中有疑問的資料刪除 (因Sheet2的資料澄清後,需要在匯回Sheet1中,會避免資料重覆的情況下,需要先行刪除)
3.Sheet2的資料澄清後,需要在匯回Sheet1中 (還沒有寫)
我在VBA寫法
1.將Sheet1中有疑問的資料轉到sheet2中
x = 0
K = 0
Do Until Sheet1.Cells(7 + x, 12) = ""
If Sheet1.Cells(7 + x, 6) <> "" Then
Sheet1.Rows(7 + x).Copy
Sheet2.Select
Sheet2.Rows(7 + k).Select
ActiveSheet.Paste
k = k + 1
End If
2. 將Sheet1中有疑問的資料刪除
x = 0
Do Until Sheet1.Cells(7 + x, 12) = ""
For J = 0 To x
If Sheet1.Cells(7 + J, 6) <> "" Then
Sheet1.Rows(7 + J).Delete
End If
Next J
x = x + 1
Loop
可是這樣的寫法在執行上比較慢,請問大大是否有較好的方法
另外第3.將資料匯回sheet1也有點卡住,盼能夠有提點一下
這是我的寫法,不過我要貼的是從空白的地方接資料,但是執行後,檢查資料,卻沒有成功
x = 0
k = 0
Do Until Sheet2.Cells(7 + x, 6) = ""
If Sheet1.Cells(7 + k, 12) = "" Then
Sheet2.Rows(7 + x).Copy
Sheet1.Select
Sheet1.Rows(7 + k).Select
ActiveSheet.Paste
x = x + 1
End If
k = k + 1
Loop作者: Hsieh 時間: 2010-11-26 12:29
忘了還有刪除:
Private Sub CommandButton1_Click() '匯出與刪除
With Sheet1
.Range("f6:f" & .[g65536].End(3).Row).SpecialCells(2).EntireRow.Copy Sheet2.[a7]
.Range("f6:f" & .[g65536].End(3).Row).SpecialCells(2).EntireRow.delete
End With
End Sub作者: GBKEE 時間: 2010-11-27 18:24
Private Sub CommandButton1_Click() '刪除
With Sheet1
r = .[L65536].End(xlUp).Row
Do Until r < 7
If .Cells(r, 6) <> "" or Cells(r, 15) = 0 or Cells(r, 89) = 0 Then
.Rows(r).Delete xlShiftUp '刪除
End If
r = r - 1
Loop
End With
End Sub作者: oobird 時間: 2010-11-30 20:35
Private Sub CommandButton1_Click() '匯出與刪除
With Sheet1.Range("f6").CurrentRegion.Columns(6).Offset(2) <--- 若我的條件是F欄與K欄資料符合我刪除的條件,才進行刪除的動作
On Error Resume Next
With .SpecialCells(2).EntireRow
.Copy Sheet2.Range("A" & Sheet2.Range("F" & Rows.Count).End(xlUp).Row).Offset(1)
.Delete
End With
End With
End Sub作者: GBKEE 時間: 2010-12-9 20:27