2016-03-30 28 views
0

Sanırım oldukça basit bir şeyle ilgili bir sorun yaşıyorum. Birisi lütfen yardım edebilir mi?Her değişken için ayarlama

Her döngü için "hücre" değerini nasıl ayarlayabilirim? Bir satırı sildiğimden, "hücre" sayacım atılıyor ve her çıkarıldığında bir satır atlıyor.

ben sayacı ayarlayarak bunu düzeltmek, ancak değiştirmeniz gerekiyor düşünüyorum: Set hücre = hücreyi - 1

For Each row In pipelineRange.Rows 
    For Each cell In row.Cells 
    If cell.Value = "EXIT" Then 
     cell.EntireRow.Copy Destination:=Worksheets("EXITS").Range("A" & Sheets("EXITS").Range("B" & Rows.Count).End(xlUp).row + 1) 
     Sheets("PIPELINE TRACKER").Activate 
     cell.EntireRow.Delete 
     Set cell = cell - 1 
    ElseIf cell.Value = 1 Then 
     cell.EntireRow.Copy Destination:=Worksheets("COMPLETED").Range("A" & Sheets("COMPLETED").Range("B" & Rows.Count).End(xlUp).row + 1) 
     Sheets("PIPELINE TRACKER").Activate 
     cell.EntireRow.Delete 
     Set cell = cell - 1 
    End If 
Next cell 
Next row 

cevap

1

Bunu önlemek için geriye gitmek her zaman silme. Örneğin: Biz o zaman eksi 1 menzil son satır alacak bunları birbirine eklerseniz Biz de burada pipelineRange.Rows.Count aralıktaki satır sayısını bilmek pipelineRange.Row:

For X = Range("A" & Rows.count).end(xlup).row to 2 step -1 
    If Range("A" & X).Text = "Delete Me" then rows(X).delete 
Next 

Biz burada aralığın ilk satırı biliyorum Bu belki

Sub Something() 
Dim X As Long 
For X = pipelineRange.Row + pipelineRange.Rows.Count - 1 To pipelineRange.Row Step -1 
    For Each cell In Rows(X).Cells 
     If cell.Value = "EXIT" Then 
      cell.EntireRow.Copy Destination:=Worksheets("EXITS").Range("A" & Sheets("EXITS").Range("B" & Rows.Count).End(xlUp).Row + 1) 
      Sheets("PIPELINE TRACKER").Activate 
      cell.EntireRow.Delete 'You could change this for rows(X).delete if you like 
     ElseIf cell.Value = 1 Then 
      cell.EntireRow.Copy Destination:=Worksheets("COMPLETED").Range("A" & Sheets("COMPLETED").Range("B" & Rows.Count).End(xlUp).Row + 1) 
      Sheets("PIPELINE TRACKER").Activate 
      cell.EntireRow.Delete 'You could change this for rows(X).delete if you like 
     End If 
    Next 
Next 
End Sub 
gibi

şey

İlgili konular