Skip to main content

VBA Code to Clear Cells with Zero शून्य के साथ सेल को साफ़ करने के लिए VBA कोड


# 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 Range
If Cell.Value = myValue Then Cell.Clear
Next Cell


VBA Statement Explanation

Lines #1 and #3: For Each Cell In Range | Next Cell

  1. 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.
  2. 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.
  3. 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

  1. 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).
  2. 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.
  3. 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.
  4. 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).
  5. 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).
  6. 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

Popular posts from this blog

Excel VBA Code For Clear Cell एक्सेल VBA कोड क्लियर सेल के लिए

# VBA Code to Clear Cell :- To  clear cells using VBA , use a statement with the following structure:- VBA का उपयोग :-  सेल  को साफ करने के लिए Cells.Clear VBA Statement Explanation Item:  Cells. VBA Construct:  Range object. Description:  Range object representing the cells you want to clear. 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 Cells, use the Range object data type. Item:  Clear. VBA Construct:  Range.Clear method. Description:  The Range.Clear method clears the Range object you specify (Cells). Range.Clear clears the entire Range object, including values, formulas and formatting. VBA स्टेटमेंट स्पष्टीकरण 1. आइटम: सेल। VBA निर्माण: रेंज ऑब्जेक्ट। विवरण: रेंज ऑब्जेक्ट उन कोश...

Insert Multiple Blank Row मल्टीपल ब्लैंक रो डालें

👍  If you ever need to insert multiple blank rows into your data, doing it manually could be very time consuming if you have a large data set. Here’s a quick way to do this by inserting a blank row into your data after every Nth record. यदि आपको कभी भी अपने डेटा में कई रिक्त पंक्तियों को सम्मिलित करने की आवश्यकता होती है, तो मैन्युअल रूप से ऐसा करने में बहुत समय लग सकता है यदि आपके पास एक बड़ा डेटा सेट है। हर Nth रिकॉर्ड के बाद आपके डेटा में एक रिक्त पंक्ति सम्मिलित करके ऐसा करने का एक त्वरित तरीका है। Add a column  to the right of your data. If the helper column is in  E1 , then add this formula into  E2  and copy it down to the end of the data. Change N to a number (5 if you want every 5th row etc…). =MOD(ROW(E2)-ROW($E$1)-1,N) Now  highlight  the whole column. Go to the  Home  tab in the ribbon. In the  Editing  section, press the  Find & Select  button. In the drop down menu, select  Find . You ...

Basic Excel Learn by Online ऑनलाइन द्वारा बेसिक एक्सेल जानें