अंतिम डैश खोजें - एक्सेल टिप्स

विषय - सूची

आज एक पागल सवाल है। आपके पास भाग संख्याओं का एक कॉलम है। भाग संख्या में 4 से 7 डैश हैं। आप पहले डैश के बाद और उसके बाद के भाग संख्या का केवल भाग निकालना चाहते हैं, लेकिन अंतिम डैश शामिल नहीं है। यह एक द्वंद्वयुद्ध एक्सेल एपिसोड है।

वीडियो देखेंा

  • लक्ष्य पहला और अंतिम डैश ढूंढना है और बीच में सब कुछ रखना है
  • यहाँ कठिन हिस्सा अंतिम पानी का छींटा है
  • बिल विधि 1: फ्लैश भरें
  • पहले कुछ में मैन्युअल रूप से भरें (डैश के विभिन्न नंबरों के साथ कुछ)
  • उसके नीचे रिक्त सेल का चयन करें
  • Ctrl + E से Flash Fill
  • माइक विधि 2:
  • पावर क्वेरी का उपयोग करें
  • Excel 2016 में, Power Query Excel 2016 में Get & Transform समूह में है
  • Excel 2010 और 2013 में, Microsoft से पावर क्वेरी डाउनलोड करें। यह रिबन में एक नया पावर क्वेरी टैब बनाता है
  • अपने डेटा को Ctrl + T का उपयोग करके तालिका में कनवर्ट करें
  • पावर क्वेरी में स्प्लिट डेटा का उपयोग करें - पहले बाईं ओर डैश पर विभाजित करने के लिए, फिर दाएं-सबसे डैश पर विभाजित करने के लिए
  • बिल विधि 3:
  • VBA फ़ंक्शन जो अंतिम डैश खोजने के लिए सेल के अंत से पुनरावृत्त होता है
  • माइक विधि 4:
  • Nth डैश का स्थान खोजने के लिए SUBSTITUTE का उपयोग करें
  • SUBSTITUTE एकमात्र पाठ फ़ंक्शन है जो आपको एक इंस्टेंस संख्या निर्दिष्ट करने की अनुमति देता है
  • यह जानने के लिए कि किस संख्या का उपयोग करें =LEN(A2)-LEN(SUBSTITUTE)

वीडियो ट्रांसक्रिप्ट

बिल: अरे। वापसी पर स्वागत है। यह एक और द्वंद्वयुद्ध एक्सेल पॉडकास्ट का समय है। मैं MrExcel से बिल जेलन हूं। (मैं ExcelIsFun से माइक गिर्विन से जुड़ूंगा। यह हमारा - 00:03 है) एपिसोड 185: पहले से - अंतिम से - अर्क।

ठीक है। आज का प्रश्न अनवर द्वारा YouTube पर भेजा गया है। मैं पहली से आखिरी तक सब कुछ कैसे निकाल सकता हूं - और इस डेटा को यहां देखें। 3, 5, 6, 7 डैश, कहीं से भी भारी संख्या में डैश हैं?

तो, मेरा पहला विचार है, ठीक है, हे, यह वास्तव में पहले को खोजने के लिए आसान है - है ना? A2 के बाएँ या = MID का मध्य और फिर -, +1 ठीक है, लेकिन अंतिम पाने के लिए - कि मेरे सिर पर चोट लगने वाली है, सही, क्योंकि, ठीक है, हमारे पास कितने डैश हैं? हम A2 की SUBSTITUTE ले सकते हैं, डैश की जगह ले सकते हैं, और उस की लंबाई, मूल लंबाई की तुलना कर सकते हैं। यह मुझे डैश की संख्या बताता है, लेकिन अब मुझे पता है कि कौन - 2, 3, 4, 5 वां, खोजने के लिए, लेकिन क्या मैं विंड का उपयोग करता हूं?

मैं VBA में जाने के लिए तैयार था, है ना? यह मेरी घुटने की प्रतिक्रिया है। मैंने कहा, एक सेकंड रुकिए। मैंने कहा, अनवर, आप एक्सेल के किस संस्करण में हैं? वह कहता है, मैं एक्सेल 2016 में हूं। मैंने कहा, यह सुंदर है। यदि आप Excel 2013 या नए में हैं, तो हम इस महान नई सुविधा का उपयोग कर सकते हैं जिसे फ्लैश फिल कहा जाता है। फ्लैश फिल के साथ, हमें बस इसे एक पैटर्न देना है, और मैं इसे पर्याप्त पैटर्न देने जा रहा हूं, इसलिए ऐसा नहीं है कि मैं दो डैश के साथ एक ले रहा हूं और दो बार कर रहा हूं। मैं यह सुनिश्चित करना चाहता हूं कि मेरे पास इस तरह से कुछ अलग डैश हैं। Excel टीम पर चाड जानता है कि मैं क्या देख रहा हूँ। चाड का आदमी जिसने फ्लैश भरने के लिए तर्क लिखा था। तो, मुझे उनमें से लगभग 3 मिलते हैं और फिर CONTROL + E डेटा और फ़्लैश फ़िल का उपयोग करने के लिए शॉर्टकट है, और, निश्चित रूप से, यह ऐसा लगता है जैसे उसने सही काम किया हो। ठीक है, माइक।देखते हैं आपके पास क्या है।

माइक: धन्यवाद, MrExcel। हाँ। फ्लैश जीत जीत। यह सुविधा वहीं, फ्लैश फिल, आधुनिक एक्सेल टूल में से एक है जो बस अद्भुत है। यदि यह एक बार का सौदा है और आपके पास एक सुसंगत पैटर्न है, तो हे, यही वह तरीका है जो मैं इसे करूंगा।

अरे, अगली चादर पर चलते हैं। अब, फ्लैश फिल का उपयोग करने के बजाय, हम वास्तव में पावर क्वेरी का उपयोग कर सकते हैं। अब, मैं एक्सेल 2016 का उपयोग कर रहा हूं, इसलिए मेरे पास GET & TRANSFORM समूह है। वह पावर क्वेरी है। पुराने संस्करणों में, 2013 (10 से 2:30 तक), आपको वास्तव में मुफ्त पावर क्वेरी ऐड-इन डाउनलोड करना होगा।

अब, काम करने के लिए पावर क्वेरी प्राप्त करने के लिए, इसे एक्सेल टेबल में बदलना होगा। अब, फिर से, मैं फ्लैश फिल का उपयोग करूंगा यदि यह एक बार का सौदा था। आप पावर क्वेरी का उपयोग कब करेंगे? ठीक है, अगर आपके पास वास्तव में बड़ा डेटा था या किसी बाहरी स्रोत से आ रहा था, तो यह जाने का रास्ता होगा, या आप इस तरह से भी बेहतर कर सकते हैं जैसे कि फ्लैश भरने के लिए 3 या 4 उदाहरण टाइप करें क्योंकि, पावर क्वेरी के साथ, हम कर सकते हैं विशेष रूप से कहते हैं कि पहले खोजें - और अंतिम खोजें -।

अब, मैं इसे एक्सेल टेबल में बदलने जा रहा हूँ। मेरे पास एक एकल कक्ष चयनित है, चारों ओर खाली कक्ष। मैं INSERT, TABLE पर जाता हूं, या आप कीबोर्ड का उपयोग करते हैं, कंट्रोल + टी। मैं OK या ENTER क्लिक कर सकता हूं। मैं इस तालिका का नाम देना चाहता हूं, इसलिए मैं PROPERTIES में TABLE TOOLS, DESIGN तक जाऊंगा। मैं इस STARTKEYTABLE और ENTER को कॉल करने जा रहा हूं। अब मैं डेटा पर वापस जा सकता हूं, इसे FROM TABLE बटन का उपयोग करके पावर क्वेरी में ला सकता हूं। मेरा कॉलम है। नाम है। मैं यह नाम नहीं रखना चाहता क्योंकि उत्पादन एक्सेल को निर्यात किया जाएगा और मैं इसे एक अलग नाम देना चाहता हूं। तो, मैं इसे CLEANEDKEYTABLE कहूंगा। मुझे उस प्रकार की आवश्यकता नहीं है। मैं सिर्फ स्रोत को देख रहा हूं। अब मैं कॉलम पर क्लिक कर सकता हूं और ठीक घर में, SPLIT बटन है। मैं SPLIT, BY DELIMITER कह सकता हूं। ऐसा लगता है कि यह पहले से ही अनुमान लगाया गया है। मैं'मीटर बाएँ-सबसे कहने के लिए जा रहा हूँ। ओके पर क्लिक करें।

अब, अगर मैं यहाँ देखता हूँ तो मुझे बदला हुआ प्रकार दिखाई देता है। मुझे इसकी आवश्यकता नहीं है इसलिए मैं उस कदम से छुटकारा पाने जा रहा हूं। मेरे पास केवल DELIMITER द्वारा SPLIT COLUMN है। अब, मैं इसे फिर से करने जा रहा हूं, लेकिन यहां SPLIT बटन का उपयोग करने के बजाय, SPLIT COLUMN, BY DELIMITER पर राइट क्लिक करें, और उस पर नजर डालें। हम इसे RIGHT-MOST DELIMITER द्वारा विभाजित करना चुन सकते हैं। ओके पर क्लिक करें। अब, मुझे इन दो कॉलमों की आवश्यकता नहीं है, इसलिए मैं उस कॉलम पर राइट क्लिक करने जा रहा हूं, जिसे मैं रखना चाहता हूं, अन्य कॉलम को हटा दें। मैं वास्तव में इस परिवर्तनित X को X करने जा रहा हूं। यह कहना है कि क्या आप चाहते हैं कि आप इसे प्राप्त करना चाहते हैं? मैं कह रहा हूँ, हाँ, DELETE। मेरा स्वच्छ डेटा है।

अब मैं CLOSE & LOAD पर आ सकता हूं। बंद और लोड करने के लिए। यह नया आयात संवाद बॉक्स है। यह लोड करने के लिए कहता था, लेकिन मैं इसे एक मेज पर लोड करना चाहता हूं, एक कार्यकारी काम पर। पतन बटन पर क्लिक करें। मैं C1 का चयन करने जा रहा हूं, अनोलॉग्स, ओके पर क्लिक करें, और वहां हम जाते हैं। हमारे डेटा को साफ़ करने के लिए पावर क्वेरी और हम चाहते हैं कि बस डेटा प्राप्त करें। ठीक है। मैं इसे वापस फेंक दूंगा।

बिल: वहाँ बिंदु सही है, राइट-स्प्लिट DELIMITER इन स्प्लिट रंग द्वारा DELIMITER, पावर क्वेरी में शांत विशेषताओं में से एक है। वह तो कमाल है।

Alright. My knee-jerk reaction -- VBA UDF (unintelligible - 05:34) really easy to do VBA. Switch over to ALT+F11. INSERT a MODULE. In that module, type this code. I'm going to (create a - 05:43) brand new function, I’m going to call it MIDPART, and I'm going to pass it some text, and then what I'm going to do is I'm going to go from the last character in that cell from the length of MYTEXT back to 1, STEP -1 and look at that character. So, the MID of MYTEXT, that variable i, tells us which character we're looking at for length of 1. Is it a -? As soon as I find a -, I'm going to take the LEFT of MYTEXT starting at character i - 1, so I get rid of everything for that last - all the way out, and then, make sure I don't go keep looking for more dashes, the EXIT FOR will get me out of this (unintelligible - 06:17) loop, and from there is the easy part. We're just going to take the MYTEXT, start at the MID of MYTEXT, (where I use the - 06:26) use the function FIND to find the first -, go 1 more than that, and return that back.

So, let's go back, ALT+Q, to return to Excel. = MIDPART tab of that, and it looks like it's working. Copy that down. Mike, do you have another one? (=MIDPart(A2))

Mike: Well, I do have another one,, but it's going to be one long formula -- not as short as that UDF. Alright, let's go over to the next sheet. Now, if we're going to do a formula and we have some text and there are always a different number of delimiters, somehow, I need to get the position of that last delimiter.

Now, this is going to take a few steps but I'm going to start with the SUBSTITUTE function. I'm going to look through that text, , the old text I want to find is in ”, that -, , and what do I want to put in its place or substitute? “”. That will put nothing in. Now, if I ) and CONTROL+ENTER, what is that going to do? (=SUBSTITUTE(A2,“-”,“”))

Well, now I can take the length of this and subtract it from the length of this item. That will tell me how many delimiters there are. F2, and right at the beginning, I'm going to type the length of that. That will give me the full length - the length of that dashless text, ), CONTROL+ENTER, double click, and send it down. that tells me how many delimiters there are for this text. There are 6. (=LEN(A2)-LEN(SUBSTITUTE(A2,“-”,“”)))

Now I'm going to use that sixth now inside of substitute to put a different character right at the sixth listing of the delimiter, F2, and if I type SUBSTITUTE, what we want to notice is this function has an instance number. If you look at other text functions like search and find, they don't have an instance number. Substitute is the only one I can think of that actually lets you specifically say which instance of a delimiter you want to deal with. Here's the text, ,. Old text is in “ a -, and I need to pick for the new text some character that will never be in this text ring. I'm going to choose, like, or something like that, , and that's where instance number comes in, ), CONTROL+ENTER, and there it is. If I double click and send it down, it's always putting that in the position of the last delimiter. (=SUBSTITUTE(A2,“-”,“^”,LEN(A2)-LEN(SUBSTITUTE(A2,“-”,“”))))

Now I need to figure out, in each one of these, what position it is in. F2. I'm going to use the SEARCH function. SEARCH. I type S and tab. Now, search and find are the same except for search is not case-sensitive. In this case, either one would be fine because the text I'm looking for is in “, that ^, ”, , within that text. By the way, the reason that I use search instead of find is because S tab gets me search but F I tab will get me find. So, it's like one character less when typing it out. CONTROL+ENTER, double click and send it down, and now it tells me, in the 27th position is that last delimiter. (=SEARCH(“^”,SUBSTITUTE(A2,“-”,“^”,LEN(A2)-LEN(SUBSTITUTE(A2,“-”,“”)))))

Now, I'm going to take this approach for these text items. I'm now going to use the left function and get everything from the very beginning all the way up to that position. That will get rid of that last little bit. Now, actually, search tells us 27 which is right there and we only want to go to 26. So, F2, and, at the end, I'm going to - 1, CONTROL+ENTER, double click and send it down. Now, I can use the left function. F2. LEFT. There it is, left of that, ,. That's how many characters. ), CONTROL+ENTER, double click and send it down. So, now, we have gotten rid of the last little bit after the last delimiter in every cell. (=LEFT(A2,SEARCH(“^”,SUBSTITUTE(A2,“-”,“^”,LEN(A2)-LEN(SUBSTITUTE(A2,“-”,“”))))-1))

Now all I need to do is replace the first four characters, first four characters, first three characters. Now, I can use the search function on the original text because it can find the - which is three and I'll tell replace, please go, from the first character, three characters in and replace it with nothing, F2, and right at the beginning, I'm going to type REPLACE. There's the old text. Now watch this. I want to give myself a little bit more breathing room. I'm just going to artificially pick a space, ALT+ENTER. That's kind of like we do in DAX. Now I just have more breathing room. That's the old text, ,. The starting number, I need to always start at the first position so I simply type 1, , and I need to find that first - which represents number of characters. So, S tab, “-” , through… within that text, that search will find 4, 4, 3. That will work. ) and then , new text “”. That will put nothing in those first characters. ). I have the entire column highlighted so I can populate this edited formula with CONTROL+ENTER, and there we go. All the way down, we’re extracting everything between the first and the last -. (=REPLACE(LEFT(A2,SEARCH(“^”,SUBSTITUTE(A2,“-”,“^”,LEN(A2)-LEN(SUBSTITUTE(A2,“-”,“”))))-1),1,SEARCH(“-”,A2),“”))

Now, the only reason we want to be crazy like that with formulas is if we wanted the formula result to instantly update whenever we changed anything, so if I type -00, instantly it updates. Power query and flash fill will not automatically update, alright? Send it back to.

Bill: Well, that was one heck of a formula. Like, substitute was the trick. I had used substitute in the first step but didn't see that it had the instance number. Alright, so, we have four different methods here today. My first method is flash fill. Select first few, select the blank box below that, and then CONTROL+E to flash fill. Mike's method, use power query. I love that, especially the split data letting you use the leftmost - and then the rightmost -. My live seminars always talk about this one feature. Should be a finalist for the Nobel Prize for the best excel feature. It wouldn't win but it would be in one of the top five, I'm sure. My method number three, VBA function, a UDF user-defined function, that iterates from the end of the cell, and then, Mike's method, the awesome formula method. Use substitute to find the location of the nth - and then pass that answer back into substitute that tells you which instance number to look from. Brilliant.

अच्छा, तुम वहाँ जाओ। मैं सभी को धन्यवाद देना चाहता हूं। हम आपको अगली बार किसी अन्य द्वंद्वयुद्ध एक्सेल पॉडकास्ट से और ExcelIsFun के लिए देखेंगे।

फ़ाइल डाउनलोड करें

यहाँ नमूना फ़ाइल डाउनलोड करें: Duel185.xlsm

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