Ads 468x60px

Wednesday, October 24, 2012

Even faster ways to Extract file name from path [quick tip]

Even faster ways to Extract file name from path [quick tip]:
The best thing about Excel is that you can do the same thing in several ways. Our yesterdays problem – Extracting file name from full path is no different. There are many different ways to do it, apart from writing a formula. Learn these techniques to be a data extraction ninja.

1. Using Find Replace

Suggested by Iain in the comments yesterday, I love this technique for its simplicity and awesomeness.
  1. Select all the file paths
  2. Press CTRL+H
  3. Type *\ in find field
  4. Leave the replace field empty.
  5. Click on Replace all.
  6. Done!
It is that simple. Do not believe me? See this demo.
Extract file name from full path using find replace - Excel tip
Thanks Iain for teaching us this trick.

2. Using Text to columns utility

Buried inside heap of features in Excel is this beautiful Text to columns utility, that can take any text and convert it in to many columns based on the delimiter you specify. [more uses of text to columns]
This is how we can use it:
  1. Select all the file path cells
  2. Go to Data > Text to columns
  3. Chose “Delimited” in step 1 and click next.
  4. Specify delimiter as \
    Text to columns settings for extracting file name from full path - Excel
  5. Click Finish
  6. You will get all folders in to separate cells and file name in last cell.
  7. Now use a formula like =INDEX($C3:$O3,COUNTA($C3:$O3)) to extract the last cell’s value ie file name
  8. Done!
Extracting file name from path using text to columns utility and formulas - how to?

3. Using UDFs

While our formula method tends to be very long or very complicated, we can use 1-2 line VBA to get the file name from a full path. There are many ways to skin this cat in VBA, but 2 easiest methods are,
For both methods below, you first need to insert a new module and add the code in that.

Using InStrRev

As suggested by Daniel Ferry in the comments.
Public Function ParseFile(sPath As String) As Variant

ParseFile = Array(Mid$(sPath, 1 + InStrRev(sPath, “\”)), Mid$(sPath, 1 + InStrRev(sPath, “.”)))

End Function

Note: this UDF returns an array for file name & extension. So you need to enter it in 2 cells together.
The InStrRev() built in function searches for \ in the sPath from end and returns the first occurrence’s position.

Using split

As suggested by PPH in comments,



Function ExtractFileName(filespath) As String

Dim x As Variant

x = Split(filepath, Application.PathSeparator)

ExtractFileName = x(UBound(x))
End Function

What is your favorite method?

For most of my data cleaning needs, I use a mix of text to columns, find-replace or VBA. In rare cases, I rely on a formula. This is because data cleaning or extraction is usually one time step and figuring out a complex formula is not good idea in such cases.
What about you? How do you go about extracting filenames, dates, numbers etc. buried in text? What method do you use often? Please share with us in comments.

More tips on Data Extraction:

Extract file name from full path using formulas

Extract file name from full path using formulas:
Today lets tackle a very familiar problem. You have a bunch of very long, complicated file names & paths. Your boss wants a list of files extracted from these paths, like below:
Extracting file names from full path using Excel formulas - how to?
Of course nothing is impossible. You just need correct ingredients.
What we need to extract file names from full path text - Excel formulas
I cannot help you with a strong cup of coffee, so go and get it. I will wait…
Back already? well, lets start the formula magic then.

Extracting file name from a path

If you observe the file paths carefully, to extract the file name, we need to know,
  • Position of last \ in the full path text
Of course there are many methods find where the last \ is. You can find a very excellent summary of these techniques in our formula forensics #21 – finding the 4th slash.
Today, let us see a new technique (well, sort of).

Finding the position of last \ using formulas

Before writing any formula, first let me clarify the only assumption:
  • File path is in cell B4
Now, last \ is nothing but first \ when read from right.
Read that line again.
Got it? Good, lets move on.
How do we find the first \ from right?
If we can list down all individual characters from path right to left, then we just have to find the first \ in that.

Listing down individual characters from a given text

To get 5th character from text in B4, we can use MID formula like this:
=MID(B4,5,1)
Suppose you want both 5th and 6th characters from B4, you can use:
=MID(B4,{5,6},1)
This formula returns an array of 5th and 6th characters from the text in B4.
Cool, extending the logic, =MID(B4, {6,5},1) would give 6th & 5th characters in B4.
Idea!
If we can replace {6,5} with decreasing numbers starting from length of text B4 all the way to 1, then we can list all characters in B4, right to left.
But this leads us to next problem – listing numbers from a specific value (length of B4) to 1 in descending order.

Listing numbers from n to 1 in that order

We can use ROW() formula to generate sequence of numbers like this:
=ROW(1:10) will give {1,2,3…,10}
note: this returns an array, so you need to use it with Ctrl+Shift+Enter
So if we can use =ROW(1:LEN(B4)) we could get numbers from 1 to length of text in B4 {1,2….LEN(B4)}
Unfortunately this will not work as 1:LEN(B4) is not a valid reference.
But we can fix that with INDIRECT, like this:
=ROW(INDIRECT(“1:” & LEN(B4)))
Tip: INDIRECT formula lets you construct a reference by using values in other cells as shown above.
Alternative: You can also use OFFSET to get the same result like this: =ROW(OFFSET($A$1,,,LEN(B4))). More on OFFSET here.

But wait…

So far, we have only generated numbers from 1 to n. But we need numbers from n to 1.
No sweat, we just subtract the numbers {1,2…n} from n+1 to get the list {n,n-1,n-2….2,1}
Like this:
=LEN(B4)+1 – ROW(INDIRECT(“1:” & LEN(B4)))

Using these numbers to list characters in file path in reverse order

Take a sip of that coffee, its getting cold!
Now, lets integrate our numbers in to MID like this:
=MID(B4, LEN(B4)+1 – ROW(INDIRECT(“1:” & LEN(B4))), 1)
The blue portion gives you numbers {n…2,1}
The orange portion gives you letters from right to left.

But we wanted the last \

Oh right. We do not need these letters from right to left. We instead want to find the last \ in our file path. So now we just ask Excel where the first \ is in this reversed text.
=MATCH(“\”, MID(B4, LEN(B4)+1 – ROW(INDIRECT(“1:” & LEN(B4))), 1), 0)
Blue portion gives you letters in reverse order
Orange portion finds the first \ in that.
Tip: Learn more about MATCH formula.

Extract the file name

Once you know where the last \ is, finding the file name is easy.
use =MID(B4, position_of_last_slash + 1, LEN(B4))
We need to +1 because we do not want the slash in our file name.

Demo of the entire formula in action

Okay, lets see all these steps in action in one go.
Extract file name from full path using Excel formulas - Demo

How to find the extension?

Extension is few letters added at the end of file to indicate its type. For example, excel files usually have xls, xlsx, xlsm as extension.
So how to find this extension?
Extension & file name are separated by a dot .
But often file name itself can have a dot.
In other words, Extension is text in the file name followed by last dot.
Sounds like same problem as finding the last \ and extracting file name. So I will skip the details.
But assuming the file name is in D4, extension can be found with =RIGHT(D4,MATCH(“.”,MID(D4,LEN(D4)-ROW(INDIRECT(“1:”&LEN(D4))),1),0))

NOTE on both formulas

Both file name & extension formulas are array formulas. This means after typing them, you need to press Ctrl+Shift+Enter to see correct result.

Bonus tip: Getting the file names & path from a folder

If you ever want to list down all files in a folder use this.
  1. Open command prompt (Start > Run > Cmd or Start > Cmd)
  2. Go to the folder using CD
  3. Type DIR /s/b >files.csv
  4. Close command prompt
Now you can see all the files in that folder in files.csv. Double click on it to open in Excel and run your magic :)

Download Example workbook

Click here to download the example workbook. The file uses slightly different formulas. But works just the same. Examine it and learn more.

How do you extract file names & as such?

Do you use formulas or do you rely on some other technique to extract portions of text like file names, mail addresses etc. Please share your tips & ideas using comments.

Extract often? You will dig this.

Analysts life is filled with 3 Es – extraction, exploration & explanation. And like a good assistant, Excel helps you in all 3.
If you find yourself with a shovel, bucket and boat load of data often, you are going to enjoy these articles:

Saturday, October 20, 2012

Please help me design our new product: Vitamin XL

Please help me design our new product: Vitamin XL:
Hello friends, fans & well wishers of Chandoo.org,
I am happy to announce our new product – Vitamin XL, a membership program for you. I want to make sure that Vitamin XL offers you the best possible features & value. I need your help in designing this product. Please read this short article and give me your feedback.
Vitamin XL - Membership Program from Chandoo.org

What is Vitamin XL?

Just like vitamins you give you strength and health, Vitamin XL ups your Excel mojo, gives you new ideas & powers. Here is what I have in mind:
Vitamin XL is a membership program with 3 distinct benefits
  1. Excel Training
  2. Excel Resources
  3. Excel user community

1. Excel Training

There is no such thing as 100% knowledge. More so when you are talking about a technical & versatile platform like Excel. That is why I have included many aspects in our Excel training part.
  • Excel School & VBA Classes forever: Access all our Excel School, VBA classes & Dashboard lessons – more than 100 videos, 100 workbooks & presentations at any time. Its like having an Excel trainer on call. Just login when you want to brush up on any area of Excel (or VBA) and you are ready to go.
  • Monthly video class: Every month a new concept or use of spreadsheets will be explained using videos. These lessons will be highly practical with lots of details & novel uses of Excel.
  • Live Webinars: Once in a while, we will have a webinar. The purpose is 2 fold – (1) Teach you a new concept (2) Take up questions from you. I am also planning to invite fellow MVPs & prominent Excel authors to this so that you can learn from them too.
  • Articles: Over the years, I have written more than 400 articles, tutorials, tips & examples on Excel, VBA, Dashboards here at Chandoo.org. As a Vitamin XL member, you can access all these articles & many more right from your membership area. I will be curating the articles so that you can learn about any area of Excel with ease.

2. Excel Resources

While we all want to learn, often we don’t have time to understand a concept and apply it. That is where our resources section comes in. As a Vitamin XL member, you will get:
  • Excel Vault: Imagine walking in to a vault where you can find an example or template on almost any aspect of your Excel use. That is our Excel vault. To start with, the vault will contain more than 400 excel workbooks containing formula tutorials, chart templates, models, macro examples, dashboards, excel technique demos etc. The best thing is every month, we will be adding more files to it.
  • Template & Add-in Gallery: This is where you can find dozens of templates, ready to use macros for your work situations. Download, Deploy & Delight your users.

  • Books & Sites: There are probably 1000 books, 100s of sites of offering Excel help, instructions & ideas. But what should you choose? Every month, I will be reviewing a book or sharing a collection of useful resources with you so that you can be even more awesome.
  • eBooks & Guides: Download ebooks, handy guides, printable posters & cheat sheets. Every few months, we will be adding more guides & electronic books for you.
  • What formula is that? Struck with a formula and need help? Enter our exclusive formula section, where more than 75 day to day formulas are explained with easy to understand syntax, examples. You can also download our interactive sandbox and play with formulas yourself to learn better.

3. Excel user Community

Knowledge multiples when you share it. That is why Vitamin XL is a community. In our user community you will get:
  • Members only forum: Share your excel solutions, problems, new ideas & information with fellow members. You can also ask questions and our in-house Excel ninjas will be helping you.
  • Member directory: Learn more about fellow Excel users like you, see how they are becoming awesome using it. Connect with them and make new friends.
  • Spot light: Every now and then you come across a truly novel idea, use or example of what Excel can do. In our spot light section, you will get such wonderful ideas both from our community and around web.
  • Monthly Newsletter: Get a curated selection of latest articles, tips & examples once a month. As a Vitamin XL member, you will also get discounts and offers on any future Chandoo.org purchases.

Who is this for?

Anyone who loves Excel & Chandoo.org is going to enjoy Vitamin XL. If you are a data junkie, analyst, manager, MIS or dashboard professional, heavy-dose spreadsheet user, Excel consultant or enthusiast, then you will certainly benefit having access to Vitamin XL.

But how much?

Vitamin XL comes with 2 levels of membership:
  • Basic membership for $30 per month.
  • Advanced membership for $50 per month*.
With Advanced membership, you can access all Excel School, VBA & Dashboard videos too. Other than that, everything else remains same.
* Pricing and features are not yet finalized.

Sounds interesting? Sign-up for Vitamin XL Newsletter

If you like all of this, then go ahead and join our newsletter. I will send you more details about Vitamin XL and keep you updated about the launch.
[Click here to view this online]

What do you think about it?

I want to make sure that Vitamin XL gives you best value & features. Can you please tell me how you feel about it and what additional features would you like in it?
Please share your suggestions and feedback using comments. If you want to keep it private, please email me at chandoo.d @ gmail.com

Thank you

Thanks for your continued support to Chandoo.org. I am so humbled and happy to be in a position to share my knowledge, mistakes, ideas and progress with all of you. Special thanks to scores of Excel School & VBA class students who emailed and suggested that I create something like Vitamin XL. I am eager to roll this out very soon.
PS: Go ahead and join our Vitamin XL newsletter to stay up to date about it.

Tuesday, October 16, 2012

Last day to join Excel School + Excel Hero Academy

Last day to join Excel School + Excel Hero Academy:
As you may know, I have partnered with Daniel Ferry to offer an irresistible bundle of Excel goodness: Excel School + Excel Hero Academy.
Today is the last day to enroll in this combined program. More than hundred eager & enthusiastic bunch of participants have already joined us. As you read this, there are dozens of people becoming awesome in Excel.
If you have been waiting to enroll, now is the time. Click here to join us.
Quick Re-cap: What is ES + EHA Bundle? Read on if you want to know more about this program.

What is this course bundle & How it can help you?

Please watch below video to understand how Excel School & EHA programs can benefit you.

Who is this for?

Excel School is for you, if you are,
  • New to Excel or have been using it for last few years
  • Using Excel for data analysis, presentations, dashboard reporting & pivoting
  • Keen to know various techniques, productivity tricks, short-cuts & hints to make you awesome at work
  • Eager to become awesome at your work by using Excel
Excel Hero Academy is for you, if you are,
  • Very good at Excel but want to know advanced formulas, chart interaction, animations, workbook optimization
  • Using VBA, but want to write better macros, understand how everything works & create jaw-dropping forms & workbooks
  • A learner at heart, wants to know different ways to solve your work problems and constantly improve
  • Looking for a course that can take you cutting-edge of Excel development
Choose the bundle:
Our bundle is for you if want to start from a beginner level and move to highly advanced level in Excel & VBA.
It was so easy to be able to understand the methods. Most of the downloads can be adapted to my job and suddenly I have, in the eyes of my boss, become an excel expert. cannot think of a better or more efficient method of learning excel. I could never had learned this much from books.Thank you Chandoo.

- Terry Price

Benefits for you

We have designed this bundle to give you a lot. You get the following benefits by joining us.
  • More than 50 hours of Excel & VBA training to make you awesome at your work. Right from Excel basics to writing your own VBA classes, you get everything. The course is peppered with practical examples, tips, best practice suggestions & hacks.
  • Learn at your own pace: Whether you want to learn it slow or hungry for content, we got you covered. The course content is available 24×7 from our online classroom so that you can go thru the lessons whenever you want, wherever you are.
  • Make Dashboards that your colleagues envy: In the exclusive 8 hour module on Excel Dashboards, I teach you how to create world-class, jaw dropping Dashboard reports using nothing but Excel. This portion includes full length examples, detailed explanations & design techniques. Go ahead and make your colleagues green with envy.
  • 60 + Example workbooks: Learn by dissecting our work. Understand the lessons better by breaking apart our workbooks. Each of the files are well designed to teach you how to create workbooks that look awesome too.
  • Homework & Class Projects: No learning is complete with out testing. So we give you well thought out challenges, home work assignments & class projects. By working on these practical problems, you will sharpen your skills and be able to respond better to work problems.
  • We offer 100% Money Back Guarantee for 30 days.6 month access to our Online Classroom: Our online classroom is where all the students converge, learning from each other, discussing alternative ideas, sharing course notes,exploring homework solutions & networking with other Excel users. You can access our online classroom 24×7 for 6 months from the date you joined.
  • 30 Day Money-back guarantee: Your membership comes with a 30 day money back guarantee. If you don’t like what you see in Excel School or EHA, just drop us an email and we will refund your money. No questions asked.
The content and videos in Daniel’s class are the best I have seen.

– Wanda Norrick

Wait, we have more…,

Free Bonus - Hand Drawn Blue

FREE Bonus #1: Excel Formula Crash Course – 31 Lessons

When you join EHA or EHA + Excel School, you get my Excel Formula Crash Course. It teaches you all aspects of Excel formulas – from beginner to advanced level in just 31 bite-sized lessons. This course valued at $62, is yours for free. Just make sure you join EHA or EHA + Excel School using below links & email me to get your copy.

FREE Bonus #2: Excel PDF guides – 3 pack

When you join any Excel School or EHA option, you will get 3 PDF guides. These are,
  1. Excel Formula Cheat sheet – One page quick reference guide to common formulas, reference styles, error messages.
  2. Keyboard Shortcut poster – Two page poster to remind you important productivity shortcuts when using Excel.
  3. Chart design e-book – 25 page guide to creating awesome Excel charts in simple steps.

FREE Bonus #3: Interviews with Excel Experts

To make Excel School even more awesome, I have asked fellow Excel experts, MVPs to share their tips. With any Excel School enrollment, you get:
  • Interview with Debra Dalgleish – Excel MVP & author on Pivot Tables
  • Interview with Mike Alexander – Excel MVP & author on Excel Access Integration
  • Interview with Robert Mundigl – Excel expert & blogger on Excel Dashboards
These are some of the top most experts on Excel in world. By learning from these experts, you widen your Excel perspective and become even more awesome at what you do.

Go ahead and join us

Please click here to enroll.
Here is a handy timer to tell you how much time is left. :)

Thank you

Thank you so much for your continued support to Chandoo.org. I am glad to be a partner in your quest for awesomeness. Your desire to learn more & become better motivates me in running Chandoo.org. Thank you.
PS: We will not be offering this bundle for at least another year. Go ahead and grab it while its available. Click here.

Monday, October 15, 2012

Last day to join Excel School + Excel Hero Academy

Last day to join Excel School + Excel Hero Academy:
As you may know, I have partnered with Daniel Ferry to offer an irresistible bundle of Excel goodness: Excel School + Excel Hero Academy.
Today is the last day to enroll in this combined program. More than hundred eager & enthusiastic bunch of participants have already joined us. As you read this, there are dozens of people becoming awesome in Excel.
If you have been waiting to enroll, now is the time. Click here to join us.
Quick Re-cap: What is ES + EHA Bundle? Read on if you want to know more about this program.

What is this course bundle & How it can help you?

Please watch below video to understand how Excel School & EHA programs can benefit you.

Who is this for?

Excel School is for you, if you are,
  • New to Excel or have been using it for last few years
  • Using Excel for data analysis, presentations, dashboard reporting & pivoting
  • Keen to know various techniques, productivity tricks, short-cuts & hints to make you awesome at work
  • Eager to become awesome at your work by using Excel
Excel Hero Academy is for you, if you are,
  • Very good at Excel but want to know advanced formulas, chart interaction, animations, workbook optimization
  • Using VBA, but want to write better macros, understand how everything works & create jaw-dropping forms & workbooks
  • A learner at heart, wants to know different ways to solve your work problems and constantly improve
  • Looking for a course that can take you cutting-edge of Excel development
Choose the bundle:
Our bundle is for you if want to start from a beginner level and move to highly advanced level in Excel & VBA.
It was so easy to be able to understand the methods. Most of the downloads can be adapted to my job and suddenly I have, in the eyes of my boss, become an excel expert. cannot think of a better or more efficient method of learning excel. I could never had learned this much from books.Thank you Chandoo.

- Terry Price

Benefits for you

We have designed this bundle to give you a lot. You get the following benefits by joining us.
  • More than 50 hours of Excel & VBA training to make you awesome at your work. Right from Excel basics to writing your own VBA classes, you get everything. The course is peppered with practical examples, tips, best practice suggestions & hacks.
  • Learn at your own pace: Whether you want to learn it slow or hungry for content, we got you covered. The course content is available 24×7 from our online classroom so that you can go thru the lessons whenever you want, wherever you are.
  • Make Dashboards that your colleagues envy: In the exclusive 8 hour module on Excel Dashboards, I teach you how to create world-class, jaw dropping Dashboard reports using nothing but Excel. This portion includes full length examples, detailed explanations & design techniques. Go ahead and make your colleagues green with envy.
  • 60 + Example workbooks: Learn by dissecting our work. Understand the lessons better by breaking apart our workbooks. Each of the files are well designed to teach you how to create workbooks that look awesome too.
  • Homework & Class Projects: No learning is complete with out testing. So we give you well thought out challenges, home work assignments & class projects. By working on these practical problems, you will sharpen your skills and be able to respond better to work problems.
  • We offer 100% Money Back Guarantee for 30 days.6 month access to our Online Classroom: Our online classroom is where all the students converge, learning from each other, discussing alternative ideas, sharing course notes,exploring homework solutions & networking with other Excel users. You can access our online classroom 24×7 for 6 months from the date you joined.
  • 30 Day Money-back guarantee: Your membership comes with a 30 day money back guarantee. If you don’t like what you see in Excel School or EHA, just drop us an email and we will refund your money. No questions asked.
The content and videos in Daniel’s class are the best I have seen.

– Wanda Norrick

Wait, we have more…,

Free Bonus - Hand Drawn Blue

FREE Bonus #1: Excel Formula Crash Course – 31 Lessons

When you join EHA or EHA + Excel School, you get my Excel Formula Crash Course. It teaches you all aspects of Excel formulas – from beginner to advanced level in just 31 bite-sized lessons. This course valued at $62, is yours for free. Just make sure you join EHA or EHA + Excel School using below links & email me to get your copy.

FREE Bonus #2: Excel PDF guides – 3 pack

When you join any Excel School or EHA option, you will get 3 PDF guides. These are,
  1. Excel Formula Cheat sheet – One page quick reference guide to common formulas, reference styles, error messages.
  2. Keyboard Shortcut poster – Two page poster to remind you important productivity shortcuts when using Excel.
  3. Chart design e-book – 25 page guide to creating awesome Excel charts in simple steps.

FREE Bonus #3: Interviews with Excel Experts

To make Excel School even more awesome, I have asked fellow Excel experts, MVPs to share their tips. With any Excel School enrollment, you get:
  • Interview with Debra Dalgleish – Excel MVP & author on Pivot Tables
  • Interview with Mike Alexander – Excel MVP & author on Excel Access Integration
  • Interview with Robert Mundigl – Excel expert & blogger on Excel Dashboards
These are some of the top most experts on Excel in world. By learning from these experts, you widen your Excel perspective and become even more awesome at what you do.

Go ahead and join us

Please click here to enroll.
Here is a handy timer to tell you how much time is left. :)

Thank you

Thank you so much for your continued support to Chandoo.org. I am glad to be a partner in your quest for awesomeness. Your desire to learn more & become better motivates me in running Chandoo.org. Thank you.
PS: We will not be offering this bundle for at least another year. Go ahead and grab it while its available. Click here.

Saturday, October 13, 2012

Write a formula to check few cells have same value [homework]

Write a formula to check few cells have same value [homework]:
Lets test your Excel skills. Can you write a formula to check few cells are equal?

Your homework:

  • Let us say you have four values in cells A1, A2, A3, A4
  • Write a formula to check if all 4 cells have same value (ie A1=A2=A3=A4)
  • Your output can be TRUE/FALSE or 1/0 to indicate a match (or mis-match)
Bonus question 1:
How would you write a formula if your values are in range A1:An
Bonus question 2:
What formula would work well if the cells contain non-numeric values (text, logical etc.)

Obvious answer:

The easiest and obvious answer is to test if all them are equal. The formula is,
=AND(A1=A2,A1=A3,A1=A4)
(select the above blank line to see answer)
But can you come up with some other options to test the equality?
Click here to post your answer.
Want more Excel home works, quizzes & challenges?