2015-09-04 76 views
2

所以這可能是一個非常愚蠢的問題,但我梳理了這段代碼,我需要檢查單元格(A5,A7,A10)是否爲空我想彈出一個消息框,解釋這些字段必須填充然後繼續。這是整個代碼塊。我只是不知道在哪裏放置錯誤檢查。任何幫助將是美好的。謝謝!錯誤檢查應該去哪裏?

'Set Variables 
Products = Range("B1") + 3 'Number of Products on Sheet 
Count = 4 'Count Used to Change the Active Cell 

Do While Count <= Products 
    'Checks if Product is Add On Only 
    If Cells(Count, 17) = "yes" Then 
     If Cells(Count, 5) = "grouped" Or Cells(Count, 5) = "configurable" Then 
      'Adds the **ADD ON ONLY** and Combines the Cells to Create Main Title 
      Cells(Count, 7) = Trim("** ADD ON ONLY** " & Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6)) 
      'Copies Main Title To Short Description & Image Labels 
      Cells(Count, 37) = Cells(Count, 7) 
      'Checks if product is Child Configurable 
      If Cells(Count, 4) <> "simple - child config" Then 
       'Adds Main Title to Image Labels when Product is not Child Config 
       Cells(Count, 56) = Cells(Count, 7) 
       Cells(Count, 58) = Cells(Count, 7) 
       Cells(Count, 60) = Cells(Count, 7) 
      End If 

     Else 
      'Adds the **ADD ON ONLY** and Combines the Cells to Create Main Title 
      Cells(Count, 7) = Trim("** ADD ON ONLY** " & Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6) & " " & Cells(Count, 24)) 
      'Copies Main Title To Short Description & Image Labels 
      Cells(Count, 37) = Cells(Count, 7) 
      'Checks if product is Child Configurable 
      If Cells(Count, 5) <> "simple - child config" Then 
       'Adds Main Title to Image Labels when Product is not Child Config 
       Cells(Count, 56) = Cells(Count, 7) 
       Cells(Count, 58) = Cells(Count, 7) 
       Cells(Count, 60) = Cells(Count, 7) 
      End If 
     End If 

    'If Product Is NOT Add On Only 
    Else 
     If Cells(Count, 5) = "grouped" Or Cells(Count, 5) = "configurable" Then 
      'Adds Combines the Cells to Create Main Title 
      Cells(Count, 7) = Trim(Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6)) 
      'Copies Main Title To Short Description & Image Labels 
      Cells(Count, 37) = Cells(Count, 7) 
      'Checks if product is Child Configurable 
      If Cells(Count, 5) <> "simple - child config" Then 
       'Adds Main Title to Image Labels when Product is not Child Config 
       Cells(Count, 56) = Cells(Count, 7) 
       Cells(Count, 58) = Cells(Count, 7) 
       Cells(Count, 60) = Cells(Count, 7) 
      End If 
     Else 
      'Adds Combines the Cells to Create Main Title 
      Cells(Count, 7) = Trim(Cells(Count, 2) & " " & Cells(Count, 3) & " " & Cells(Count, 6) & " " & Cells(Count, 24)) 
      'Copies Main Title To Short Description & Image Labels 
      Cells(Count, 37) = Cells(Count, 7) 
      'Checks if product is Child Configurable 
      If Cells(Count, 5) <> "simple - child config" Then 
       'Adds Main Title to Image Labels when Product is not Child Config 
       Cells(Count, 56) = Cells(Count, 7) 
       Cells(Count, 58) = Cells(Count, 7) 
       Cells(Count, 60) = Cells(Count, 7) 
      End If 
     End If 
    End If 
    'Performs Actions on Next Cell Range 

    Count = Count + 1 

Loop 
End Sub 
+0

A5,A7,A10聲具體。如果這些單元格是空的,你真的需要執行do while循環嗎?如果單元格爲空,則不要執行do循環,否則將執行循環。 – Andez

+0

我不能看到一個單獨的引用,不僅A%,A7或A10不允許任何引用列A中的單元格。將您的錯誤檢查放在最上面。 – Jeeped

回答

1

細胞(A5,A7,A10)是空的,我想彈出一個消息框,說明這些領域在繼續之前必須填寫。

在這種情況下,我會在頂部加入了。

If IsEmpty(Range("A5").Value) And IsEmpty(Range("A7").Value) And IsEmpty(Range("A10").Value) Then 
    MsgBox ("Please fill in A5, A7, and A10 - then rerun the macro.") 
    Exit Sub 
    End If 
+0

非常感謝您的幫助 – KjosN1