# VBA Code to Clear Cells with Zero:-
To clear cells with zero within a cell range using VBA, use a macro with the following statement structure:
शून्य के साथ सेल को साफ़ करने के लिए VBA कोड
For Each Cell In RangeIf Cell.Value = myValue Then Cell.ClearNext Cell
VBA Statement Explanation
VBA Statement Explanation
Lines #1 and #3: For Each Cell In Range | Next Cell
Lines #1 and #3: For Each Cell In Range | Next Cell
- Item: For Each… In… Next.
- VBA Construct: For Each… Next statement.
- Description: The For Each… Next statement repeats the statement within the loop (line #2) for each element (Cell) in the cell range (Range) you want to search for zeroes in.
- Item: Cell.
- VBA Construct: Element of the For Each… Next statement and object variable of the Range object data type.
- Description: The Element of the For Each… Next statement is an object variable used to iterate through the elements (Cell) of the cell range (Range) you want to search for zeroes in.
If you explicitly declare an object variable to represent Cell, use the Range object data type.
- Item: Range.
- VBA Construct: Group of the For Each… Next statement and Range object.
- Description: The For Each… Next statement repeats the statements within the loop (line #2) for each element (Cell) in the Group (Range). Range is a Range object representing the cells where you want to search for zeroes.
You can usually return a Range object with constructs such as the Worksheet.Range, Worksheet.Cells (with Range.Item), Range.Offset, Range.Resize or Application.ActiveCell properties. If you explicitly declare an object variable to represent Range, use the Range object data type.
Line #2: If Cell.Value = myValue Then Cell.Clear
- Item: If… Then.
- VBA Construct: If… Then… Else statement.
- Description: The If… Then… Else statement conditionally executes a group of statements depending on the value of an expression. For these purposes:
- The If… Then… Else statement tests the specified condition (Cell.Value = myValue).
- If the condition is met and returns True: Cell.Clear is executed.
- If the condition is not met and returns False: Execution continues with the statement following the If… Then… Else statement (Next Cell).
- Item: Cell.
- VBA Construct: Object variable of the Range object data type.
- Description: Cell is an object variable used to iterate through the elements of the cell range (Range) you want to search for zeroes in. Within the If… Then… Else statement, Cell represents the individual cell the For Each… Next loop is currently iterating through.
If you explicitly declare an object variable to represent Cell, use the Range object data type.
- Item: Value.
- VBA Construct: Range.Value property.
- Description: The Range.Value property returns the value in the cell the For Each…Next loop is currently iterating through.
- Item: myValue.
- VBA Construct: Variable of a numeric data type.
- Description: myValue represents the value you want to search for and use to determine which cells to clear. Within the macro structure used in this VBA Tutorial, myValue is 0 (zero).
If you explicitly declare a variable to represent myValue, use a numeric data type such as Long, Single or Double (depending on the value you're searching for).
- Item: Cell.Value = myValue.
- VBA Construct: Condition of If… Then… Else statement.
- Description: This condition is an expression that evaluates to True or False. Cell.Value = myValue returns True or False, as follows:
- True: Value of Cell is equal to myValue (zero).
- False: Value of Cell isn't equal to myValue (zero).
- Item: Clear.
- VBA Construct: Range.Clear method.
- Description: The Range.Clear method clears the cell the For Each… Next loop is currently iterating through. Range.Clear clears the entire Range object, including values, formulas and formatting.
If you don't want to clear the entire Range object, but only its contents, formatting or cell color, please refer to the appropriate sections above.
VBA स्टेटमेंट स्पष्टीकरण
लाइन्स # 1 और # 3: रेंज में प्रत्येक सेल के लिए | अगली सेल
1. आइटम: प्रत्येक के लिए… में… अगला।
VBA का निर्माण: प्रत्येक के लिए… अगला कथन
विवरण: प्रत्येक के लिए… अगला कथन उस सेल (श्रेणी) में प्रत्येक तत्व (सेल) के लिए लूप (पंक्ति # 2) के भीतर कथन को दोहराता है जिसमें आप शून्य में खोजना चाहते हैं।
2. आइटम: सेल।
VBA का निर्माण: प्रत्येक के लिए तत्व… श्रेणी वस्तु डेटा प्रकार का अगला कथन और ऑब्जेक्ट चर।
विवरण: प्रत्येक के लिए तत्व… अगला कथन एक ऑब्जेक्ट वैरिएबल है जिसका उपयोग सेल रेंज (श्रेणी) के तत्वों (सेल) के माध्यम से पुनरावृति करने के लिए किया जाता है (आप जिस शून्य में खोजना चाहते हैं)।
यदि आप स्पष्ट रूप से सेल का प्रतिनिधित्व करने के लिए ऑब्जेक्ट चर घोषित करते हैं, तो रेंज ऑब्जेक्ट डेटा प्रकार का उपयोग करें।
3. आइटम: रेंज।
VBA का निर्माण: प्रत्येक के लिए समूह… अगला कथन और श्रेणी वस्तु।
विवरण: प्रत्येक के लिए… अगला कथन समूह (श्रेणी) में प्रत्येक तत्व (सेल) के लिए लूप (पंक्ति # 2) के भीतर विवरणों को दोहराता है। रेंज एक रेंज ऑब्जेक्ट है जो उन कोशिकाओं का प्रतिनिधित्व करता है जहां आप शून्य की खोज करना चाहते हैं।
आप आमतौर पर Worksheet.Range, Worksheet.Cells (Range.Item के साथ), Range.Offset, Range.Resize या Application.ActiveCell प्रॉपर्टी जैसे कंस्ट्रक्शन के साथ रेंज ऑब्जेक्ट वापस कर सकते हैं। यदि आप स्पष्ट रूप से श्रेणी का प्रतिनिधित्व करने के लिए ऑब्जेक्ट चर घोषित करते हैं, तो रेंज ऑब्जेक्ट डेटा प्रकार का उपयोग करें।
लाइन # 2: यदि सेल। वेल = myValue तो सेल। क्लियर
1. आइटम: यदि… तो।
VBA कंस्ट्रक्ट: अगर… फिर… एल्स स्टेटमेंट।
विवरण: यदि ... तो ... अतिरिक्त विवरण सशर्त रूप से एक अभिव्यक्ति के मूल्य के आधार पर बयानों के एक समूह को निष्पादित करता है। इन उद्देश्यों के लिए:
यदि… तो… अतिरिक्त विवरण निर्दिष्ट स्थिति का परीक्षण करता है (Cell.Value = myValue)।
यदि शर्त पूरी हो जाती है और यह सच हो जाता है: सेल। क्लियर निष्पादित हो जाता है।
यदि शर्त पूरी नहीं हुई है और गलत रिटर्न देता है: यदि निम्नलिखित कथन के साथ निष्पादन जारी रहता है, तो…… कथन (अगला सेल)।
2. आइटम: सेल।
VBA निर्माण: रेंज ऑब्जेक्ट डेटा प्रकार का ऑब्जेक्ट चर।
विवरण: सेल एक ऑब्जेक्ट वैरिएबल है जिसका उपयोग सेल रेंज (एलिमेंट) के तत्वों के माध्यम से पुनरावृति करने के लिए किया जाता है, जिसे आप जीरो के लिए खोजना चाहते हैं। यदि… उसके भीतर… तो बयान, सेल प्रत्येक के लिए व्यक्तिगत सेल का प्रतिनिधित्व करता है… अगला लूप वर्तमान में है के माध्यम से पुनरावृति।
यदि आप स्पष्ट रूप से सेल का प्रतिनिधित्व करने के लिए ऑब्जेक्ट चर घोषित करते हैं, तो रेंज ऑब्जेक्ट डेटा प्रकार का उपयोग करें।
3. आइटम: Value।
VBA कंस्ट्रक्ट: रेंज.वैल्यू प्रॉपर्टी।
विवरण: रेंज.वैल्यू प्रॉपर्टी प्रत्येक के लिए सेल में मान लौटाता है ... अगला लूप वर्तमान में इसके माध्यम से पुनरावृत्ति कर रहा है।
4. आइटम: myValue।
VBA निर्माण: एक संख्यात्मक डेटा प्रकार का चर।
विवरण: myValue उस मूल्य का प्रतिनिधित्व करता है जिसे आप खोजना चाहते हैं और यह निर्धारित करने के लिए उपयोग करते हैं कि कौन सी कोशिकाएँ साफ़ करें। इस VBA ट्यूटोरियल में प्रयुक्त मैक्रो स्ट्रक्चर के भीतर, myValue 0 (शून्य) है।
यदि आप स्पष्ट रूप से myValue का प्रतिनिधित्व करने के लिए एक चर घोषित करते हैं, तो एक संख्यात्मक डेटा प्रकार का उपयोग करें जैसे कि लॉन्ग, सिंगल या डबल (आपके द्वारा खोजे जा रहे मूल्य के आधार पर)।
5. आइटम: सेल वाल्यू = myValue।
VBA कंस्ट्रक्ट: इफ की स्थिति… फिर… एल्स स्टेटमेंट।
विवरण: यह स्थिति एक ऐसी अभिव्यक्ति है जो True या False का मूल्यांकन करती है। सेल.वायु = myValue सही या गलत रिटर्न, निम्नानुसार है:
सच: सेल का मान myValue (शून्य) के बराबर है।
गलत: सेल का मान myValue (शून्य) के बराबर नहीं है।
6. आइटम: साफ़ करें।
VBA निर्माण: रेंज। क्लियर विधि।
विवरण: Range.Clear विधि सेल को प्रत्येक के लिए साफ़ करती है ... अगला लूप वर्तमान में इसके माध्यम से पुनरावृत्ति कर रहा है। श्रेणी। क्लियर मान, सूत्र और स्वरूपण सहित संपूर्ण श्रेणी ऑब्जेक्ट को साफ़ करता है।
यदि आप संपूर्ण श्रेणी ऑब्जेक्ट को साफ़ नहीं करना चाहते हैं, लेकिन केवल इसकी सामग्री, स्वरूपण या सेल रंग, कृपया ऊपर दिए गए उपयुक्त अनुभाग देखें।
Comments
Post a Comment
Your advice or suggestions will be much appreciated and welcomed....