VBA FIND NEXT - एक्सेल VBA में फाइंडनेक्स्ट फंक्शन का उपयोग कैसे करें?

एक्सेल VBA अगला खोजें

जैसे एक्सेल में जब हम CTRL + F दबाते हैं तो एक विज़ार्ड बॉक्स पॉप अप होता है जो हमें दिए गए वर्कशीट में एक मान खोजने की अनुमति देता है और एक बार वैल्यू मिलने के बाद हम दूसरे समान मान को खोजने के लिए अगले पर क्लिक करते हैं, क्योंकि यह एक वर्कशीट फीचर है। इसे VBA में अनुप्रयोग गुण विधि के रूप में भी उपयोग कर सकते हैं।

उल्लिखित सीमा में विशिष्ट मूल्य खोजना ठीक है, लेकिन क्या होगा यदि आवश्यकता कई घटनाओं के साथ मूल्य को खोजने के लिए है। पहले के एक लेख में, हमने VBA में "फाइंड" विधि पर चर्चा की है, और यह बिल्कुल भी जटिल नहीं है, लेकिन सभी दोहराए जाने वाले घटनाओं को केवल एक्सेल VBA में "फाइंड नेक्स्ट" विधि से ही पता लगाना संभव है।

इस लेख में, हम आपको एक्सेल VBA में इस "फाइंड नेक्स्ट" का उपयोग करने का तरीका बताएंगे।

Excel VBA में अगला क्या है?

जैसा कि शब्द कहता है, '' नेक्स्ट नेक्स्ट '' का अर्थ है कि पाया गया सेल तब तक अगले मूल्य की खोज करता रहता है जब तक कि हम उस मूल सेल में वापस नहीं आ जाते हैं जहाँ हमने खोज शुरू की है।

यह "फाइंड" विधि का उन्नत संस्करण है, जो उल्लिखित सीमा में केवल एक बार मूल्य का पता लगाता है।

नीचे Excel VBA में FIND NEXT विधि का वाक्य विन्यास है।

के बाद: यह शब्द है जिसे हम खोज रहे हैं।

एक्सेल VBA में अगली विधि खोजें के उदाहरण

नीचे एक्सेल VBA में अगली विधि खोजने के उदाहरण दिए गए हैं।

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

चरण # 1 - इस डेटा में, हमें शहर का नाम "बैंगलोर" ढूंढना होगा। आइए बुनियादी दृश्य संपादक में उपप्रकार शुरू करें।

कोड:

सब रेंजनेक्स्ट_एक्सप्लिमेंट () एंड सब

चरण # 2 - सबसे पहले, चर को "रेंज" ऑब्जेक्ट घोषित करें।

कोड:

सब रेंजनेक्स्ट_एक्सप्लिमेंट () डिम रींग एज़ रेंज एंड सब

चरण # 3 - ऑब्जेक्ट चर के संदर्भ को "रेंज (" ए 2: ए 11 ") के रूप में सेट करें।

कोड:

सब रेंजनेक्स्ट_एक्सप्लिमेंट () डिम रींग अस रेंज सेट रेंग = रेंज ("ए 2: ए 12") एंड सब

चूँकि इस सूची में A2 से A11 तक कोशिकाओं की श्रेणी में हमारा शहर सूची का डेटा है, इसलिए केवल हम शहर “बैंगलोर” की खोज करने जा रहे हैं।

चूँकि हम रेंज रेन्ज को “Rng” पर सेट करते हैं, इसलिए हम हर बार RANGE (“A2: A11”) का उपयोग करने के बजाय इस वैरिएबल का उपयोग करते हैं।

चरण # 4 - RNG चर का उपयोग करें और खोज विधि खोलें।

कोड:

सब RangeNext_Example () डिम Rng अस रेंज सेट Rng = Range ("A2: A12") Rng.Find रेंज उप

चरण # 5 - FIND विधि का पहला तर्क है “क्या,” अर्थात, हम क्या उल्लेखित सीमा में खोज करने की कोशिश कर रहे हैं, इसलिए हम जो मूल्य खोज रहे हैं वह “बैंगलोर” है।

कोड:

सब RangeNext_Example () मंद रिंग रेंज रेंज Rng = रेंज ("A2: A12") Rng.Find क्या: = "बैंगलोर" अंतिम उप

चरण # 6 - यह दिखाने के लिए कि किस सेल में हमने यह मान पाया है कि एक स्ट्रिंग के रूप में एक और चर घोषित किया गया है।

कोड:

सब रेंजनेक्स्ट_एक्सप्लिमेंट () डिम रींग एज़ रेंज डिम सेल एडेडरेसिंग स्ट्रिंग सेट आरंग = रेंज ("ए 2: ए 12") आरएनजी.इंड: क्या "= बैंगलोर" एंड सब

चरण # 7 - इस चर के लिए, पाया गया सेल पता असाइन करें।

कोड:

सब रेंजनैक्स्ट_एक्सप्लिमेंट () डिम रींग इन रेंज डिम सेल एडिडरस ऐज़ स्ट्रिंग सेट रेंग = रेंज ("ए 2: ए 12")। फाइंड (क्या: = "बैंगलोर") Rng.Find व्हाट: = "बैंगलोर" सेलड्रेस्रेस = Rng.Address End Sub
नोट: RNG पता क्योंकि RNG में पाया गया मान सेल के लिए संदर्भ होगा।

चरण # 8 - अब VBA में संदेश बॉक्स में निर्दिष्ट सेल पता चर परिणाम दिखाएं।

Sub RangeNext_Example() Dim Rng As Range Dim CellAdderess As String Set Rng = Range("A2:A12").Find(What:="Bangalore") Rng.Find What:="Bangalore" CellAddress = Rng.Address MsgBox CellAddress End Sub

Step#9 - Run the code and see what we get here.

So we have found the value “Bangalore” in the cell A5. With the Find method, we can find only one cell, so instead of FIND, we need to use FIND NEXT in excel VBA.

Step#10 - We need to reference the range object variable but by using the FIND NEXT method in excel VBA.

Code:

Sub RangeNext_Example() Dim Rng As Range Dim CellAdderess As String Set Rng = Range("A2:A12").Find(What:="Bangalore") Rng.Find What:="Bangalore" CellAddress = Rng.Address MsgBox CellAddress Set Rng = Range("A2:A12").FindNext(Rng) End Sub

As you can see above, we have used the VBA FIND NEXT method, but inside the function, we have used a range object variable name.

Step#11 - Now again, assign the cell address and show the address in the message box.

Code:

Sub RangeNext_Example() Dim Rng As Range Dim CellAdderess As String Set Rng = Range("A2:A12").Find(What:="Bangalore") Rng.Find What:="Bangalore" CellAddress = Rng.Address MsgBox CellAddress Set Rng = Range("A2:A12").FindNext(Rng) CellAddress = Rng.Address MsgBox CellAddress End Sub

Step#12 - Run the macro and see what we get in the first message box.

Step#13 - The first message box shows the value “Bangalore” found in the cell A5. Click on the Ok button to see the next found value.

The second value found in A7 cell, press Ok to continue.

VBA Find Next (Using Loop)

It will exit the VBA subprocedure, but we are one more to be found in cell A10. When the values are to be found in more than one cell, then it is a better idea to use loops.

In this case, too, we have value “Bangalore” in more than one cell, so we need to include loops here.

Step#14 - First, declare two variables as the range.

Code:

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range End Sub

Step#15 - Set the reference for the first variable, as shown below.

Code:

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range Set Rng = Range("A2:A11").Find(What:="Bangalore") End Sub

Step#16 - For the second variable, set the reference by using the FIND VBA function.

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range Set Rng = Range("A2:A11").Find(What:="Bangalore") Set FindRng = Rng.FindNext("Bangalore") End Sub

Step#17 - Before we start searching for the value, we need to identify from which cell we are starting the search, for that declares the variable as a string.

Code:

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range Set Rng = Range("A2:A11").Find(What:="Bangalore") Set FindRng = Rng.FindNext("Bangalore") Dim FirstCell As String FirstCell = Rng.Address End Sub

Step#18 - For this variable, assign the first cell address.

Code:

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range Set Rng = Range("A2:A11") Set FindRng = Rng.Find(What:="Bangalore") Dim FirstCell As String FirstCell = Rng.Address End Sub

Step#19 - Now, we need to include the “Do While” loop to loop through all the cells and find the searching value.

Code:

Sub RangeNext_Example1() Dim Rng As Range Dim FindRng As Range Set Rng = Range("A2:A11").Find(What:="Bangalore") Set FindRng = Rng.FindNext("Bangalore") Dim FirstCell As String FirstCell = Rng.Address Do Loop While FirstCell Cell.Address End Sub

Inside the loop, mention the message box and VBA FIND NEXT method.

Step#20 - Below is the complete code for you.

Code:

सब FindNext_Example () डिम FindValue स्ट्रिंग स्ट्रिंग FindValue = "बंगलौर" डिम Rng As Range Set Rng = Range ("A2: A11") डिम FindRng As Range Set FindRng = Rng। FindRng.Address Do MsgBox FindRng.Address सेट FindRng = Rng.FindNext (FindRng) लूप करें जबकि FirstCell FindRng.Address MsgBox खोजें "ओवर सब" खोजें

चरण # 21 - यह सभी मिलान सेल पते दिखाता रहेगा, और अंत में, यह संदेश को नए संदेश बॉक्स में "खोज खत्म हो गया" के रूप में दिखाएगा।

याद रखने वाली चीज़ें

  • FIND विधि एक समय में केवल एक मान पा सकती है।
  • एक्सेल VBA में FIND NEXT, पहले से मिली वैल्यू सेल से अगला मान पा सकता है।
  • सीमा में सभी कोशिकाओं के माध्यम से लूप जबकि लूप का उपयोग करें।

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