2015-02-09 154 views
0

我有以下的VB,有人帮助我的工作很好,除了我现在需要添加。就目前而言,VB正在查看“C”列,如果它是空白的,它会将“A”&“B”剪切并粘贴到另一个表格中。我想要做的还包括“SHOT10”,“SHOT15”&“SHOT20”。也就是说,如果在“C”栏中也发现了这些内容,那么它们也应该被切割并粘贴到另一张纸上。修改一个VB代码以剪切和粘贴到另一个工作表

CODE

Sub ClearRange3() 

Dim myLastRow As Long 
Dim i As Long 

Application.ScreenUpdating = False 
Sheets("Absence Line").Select 
' Find last row 
myLastRow = Cells(Rows.Count, "B").End(xlUp).Row 


' Loop through range 
For i = 2 To myLastRow 
If Cells(i, "C").Value = "" Then 
    With Range(Cells(i, "A"), Cells(i, "B")) 
     .Copy 
     find_last_record = Worksheets("Duplicates").Range("A65536").End(xlUp).Row + 1 
     Sheets("Duplicates").Paste Destination:=Sheets("Duplicates").Range("A" & i) 
     .ClearContents 
    End With 
End If 
Next i 

Application.ScreenUpdating = True 
End Sub 

预先感谢任何帮助,您可以提供。

+0

您已使用vb.net标记了您的问题,但您发布的代码更像是Excel中的vba(Visual Basic for Applications)。你使用哪种语言?根据不同的语言,您的问题的答案可能会有所不同。 – Blackwood 2015-02-09 13:20:14

+0

我很抱歉 - 它实际上是vba,而不是VBA.NET – spittingfire 2015-02-09 14:42:03

回答

1

这会适合你,Or是你的朋友。

Sub ClearRange3() 

    Dim myLastRow As Long 
    Dim i As Long 

    Application.ScreenUpdating = False 
    Sheets("Absence Line").Select 
    ' Find last row 
    myLastRow = Cells(Rows.Count, "B").End(xlUp).Row 


    ' Loop through range 
    For i = 2 To myLastRow 
    If Cells(i, "C").Value = "" Or Cells(i, "C").Value = "SHOT10" Or Cells(i, "C").Value = "SHOT15" Or Cells(i, "C").Value = "SHOT20" Then 
     With Range(Cells(i, "A"), Cells(i, "B")) 
      .Copy 
      find_last_record = Worksheets("Duplicates").Range("A65536").End(xlUp).Row + 1 
      Sheets("Duplicates").Paste Destination:=Sheets("Duplicates").Range("A" & i) 
      .ClearContents 
     End With 
    End If 
    Next i 

    Application.ScreenUpdating = True 
    End Sub 
+0

感谢Jeanno,我不确定如何在那里添加“Or”。谢谢你的帮助。 – spittingfire 2015-02-09 15:21:28

相关问题