2015-12-04 49 views
2

有没有这个代码更有效的方式:检查细胞的多张数据值

Do 
TempRow = TempRow + 1 
    If (Worksheets("Source").Cells(TempRow, TempColumn) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 1) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 2) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 3) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 4) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 5) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 6) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 7) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 8) = "808" Or Worksheets("Source").Cells(TempRow, TempColumn + 9) = "808") Then 
    If (Worksheets("Source").Cells(TempRow, TempColumn) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "147" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "147") Then 
     If (Worksheets("Source").Cells(TempRow, TempColumn) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "288" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "288") Then 
     If (Worksheets("Source").Cells(TempRow, TempColumn) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "468" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "468") Then 
      If (Worksheets("Source").Cells(TempRow, TempColumn) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "661" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "661") Then 
      If (Worksheets("Source").Cells(TempRow, TempColumn) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "662" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "662") Then 
       If (Worksheets("Source").Cells(TempRow, TempColumn) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "663" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "663") Then 
       If (Worksheets("Source").Cells(TempRow, TempColumn) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 1) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 2) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 3) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 4) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 5) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 6) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 7) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 8) <> "664" And Worksheets("Source").Cells(TempRow, TempColumn + 9) <> "664") Then 
         Worksheets("Source").Cells(TempRow, 260) = "1" 
       Else: Worksheets("Source").Cells(TempRow, 260) = "0" 
       End If 
       End If 
      End If 
      End If 
     End If 
     End If 
    End If 
    End If 
Loop While Not IsEmpty(Worksheets("Source").Cells(TempRow, TempColumn)) 
+1

圣quacamole!你可以用伪逻辑编辑你的文章,以便更容易理解你想要做什么? –

+0

我同意。这看起来像是一个二进制搜索的展开循环。你能否根据你期望的代码重新提出你的问题。 –

回答

1

好,粘贴到我的VBE后,我意识到这不是因为,因为它看起来。

这是一个巨大的开始使其更有效率(和更易于阅读/编辑前进):

With Worksheets("Source") 

    Do 
    tempRow = tempRow + 1 

     If Not .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="808", lookat:=xWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="147", lookat:=xlWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="288", lookat:=xlWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="468", lookat:=xlWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="661", lookat:=xlWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="662", lookat:=xlWhole) Is Nothing _ 
      And .Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="663", lookat:=xlWhole) Is Nothing _ 
      And Cells(tempRow, TempColumn).Resize(1, 10).Find(What:="664", lookat:=xlWhole) Is Nothing Then 
       Worksheets("Source").Cells(tempRow, 260) = "1" 
     Else: Worksheets("Source").Cells(tempRow, 260) = "0" 

     End If 

    Loop While Not IsEmpty(.Cells(tempRow, TempColumn)) 

End With 
+0

调整大小是不是'(1,10)'将'TempColumn'包含到'TempColumn + 9'​​? –

+1

谢谢@ScottCraner。我正在考虑'抵消'......我们组建了一支不错的队伍!也许它的一切都以名字命名! –

相关问题