VBA Intersect - एक्सेल VBA में Intersect के उदाहरण - तरीके

विषय - सूची

एक्सेल VBA Intersect

VBA Intersect का उपयोग एक रेंज ऑब्जेक्ट प्राप्त करने के लिए किया जाता है जो दो या अधिक रेंज का एक चौराहा होता है। इंटरसेक्टिंग रेंज पॉइंट को खोजने के लिए न्यूनतम दो रेंज की आपूर्ति की जानी चाहिए। आवश्यकता के आधार पर अन्य सभी तर्क वैकल्पिक हैं।

नीचे VBA INTERSECT सूत्र का वाक्यविन्यास है।

  • आरजी 1 रेंज के रूप में: पहली इंटरसेक्टिंग रेंज।
  • Arg2 रेंज के रूप में: दूसरी प्रतिच्छेदन सीमा।

नीचे दिए गए उदाहरणों में हम कुछ उपयोगी तकनीकों को देखेंगे।

उदाहरण

उदाहरण 1

उदाहरण के लिए, नीचे दिए गए डेटा का उपयोग करें।

चरण 1: वेरिएंट को वैरिएंट के रूप में घोषित करें।

कोड:

उप Intersect_Example () वेरिएंट एंड सब के रूप में मंद MyValue

चरण 2: इस चर के लिए Intersect सूत्र के माध्यम से मान असाइन करें।

कोड:

उप Intersect_Example () वेरिएंट MyValue के रूप में मंद MyValue = Intersect (अंतिम उप)

चरण 3: बी 2 के रूप में बी 9 के लिए पहली सीमा का चयन करें।

कोड:

उप Intersect_Example () वेरिएंट MyValue = Intersect (रेंज ("B2: B9") के रूप में मंद MyValue, उप सब

चरण 4: A5 से D5 तक दूसरी श्रेणी का चयन करें।

कोड:

उप Intersect_Example () वेरिएंट MyValue = Intersect (रेंज ("B2: B9") के रूप में मंद MyValue, रेंज ("A5: D5") अंतिम उप

चरण 5: हम यहां केवल दो श्रेणियों के साथ परीक्षण कर रहे हैं। सूत्र बंद करें और VBA सेल पते के रूप में विधि का चयन करें।

कोड:

उप Intersect_Example () वेरिएंट MyValue = Intersect (रेंज ("B2: B9"), रेंज ("A5: D5") के रूप में मंद MyValue। पता अंत उप।

चरण 6: VBA में संदेश बॉक्स में मान दिखाएं।

कोड:

सब Intersect_Example () वेरिएंट MyValue = Intersect (रेंज ("B2: B9"), रेंज ("A5: D5") के रूप में मंद MyValue। पता MsgBox MyValue समाप्ति उप।

ठीक है, हम कर रहे हैं और देखें कि हमें संदेश बॉक्स में क्या मिलेगा।

हमें B5 अर्थात सेल की सीमा के प्रतिच्छेदन बिंदु के सेल पते के रूप में परिणाम मिला।

जैसे VBA INTERSECT मेथड का उपयोग करके हम कई और चीजें कर सकते हैं।

उदाहरण # 2

इंटरसेक्शन सेल का चयन करें

आपूर्ति श्रृंखला के चौराहे सेल का चयन करने के लिए नीचे दिए गए कोड का उपयोग करें।

कोड:

उप Intersect_Example2 () Intersect (श्रेणी ("B2: B9"), श्रेणी ("A5: D5"))। अंत उप चुनें।

यह आपूर्ति की सीमा के चौराहे सेल का चयन करेगा।

Example #3

Clear Content of the Intersection Cell: In order to clear the content of the intersection cell of the supplied range uses the below code.

Code:

Sub Intersect_Example2() Intersect(Range("B2:B9"), Range("A5:D5")).ClearContents End Sub

Example #4

Change the Cell Color Background and Font Color of Intersection Cell: In order to change the background color of the intersection cell and the font color of the intersection cell value using the below code.

Code:

Sub Intersect_Example2() Intersect(Range("B2:B9"), Range("A5:D5")).Cells.Interior.Color = rgbBlue Intersect(Range("B2:B9"), Range("A5:D5")).Cells.Font.Color = rgbAliceBlue End Sub

Change the Value of the Intersection Cell: Using the Intersect function, we can also change the value of that cell into something else.

In the above data, the intersect value of the range “B2:B9” & “A5:D5” is cell B5 i.e., marked with blue color. Now by supplying this range to intersect function, we can actually change the value to something else.

The below code will change the value from 29398 to “New Value.”

Code:

Sub Intersect_Example3() Intersect(Range("B2:B9"), Range("A5:D5")).Value = "New Value" End Sub

Run the code above. We will get the word “New Value” in place of 29398.

Like this, by using the Intersect function, we can play around with the middle position value of the supplied range.

Things to Remember

  • एक्सेल में, रेंज के प्रतिच्छेदन मूल्य को प्राप्त करने के लिए, हमें दो श्रेणियों के बीच में अंतरिक्ष वर्ण देने की आवश्यकता है।
  • VBA कोडिंग का उपयोग करके, हम चौराहे के मूल्य पर प्रकाश डाल सकते हैं, प्रारूपित कर सकते हैं, हटा सकते हैं या बदल सकते हैं और कई अन्य काम कर सकते हैं।
  • यदि कई पंक्तियों और स्तंभों को इंटरसेक्ट फ़ंक्शन के लिए आपूर्ति की जाती है, तो हमें मध्य दो मान मिलेंगे।

दिलचस्प लेख...