Today, while answering a reader’s email, I wrote this VBA code,
If Target.Value = "yes" Then
'do something
End If
But I realized that my code would run only the Target cell has “yes” in it. It wont run if the target cell has “YES”, or “Yes” or “YeS”.
This is because by default, all VBA comparisons are binary. That means, “yes” ≠ “Yes”.
One quick work-around for this problem is to use UCASE to convert target.value to Uppercase and then compare, like this,
If UCASE(Target.Value) = "YES" Then
'do something
End If
But this seemed painful, especially, if I had to do similar comparison at multiple places in my code, I had to use UCASE() everywhere.
If only there is an option to tell VBA how to compare?!?
Well, there is an option.
Use Option Compare Text
If you write Option Compare Text at the top of your module, all the VBA comparisons with in that module will use Text comparison instead of Binary comparison. Thus, “yes” will be equal to “YES”.
Do you use Option Compare?
There are 3 settings for Option Compare.
Option Compare Binary: This is the default setting. Compares everything at binary level.Option Compare Text: Used for situations like this.Option Compare Database: Can be used only with MS Access VBA. Uses Database Table settings to determine how to compare.
This is the first time I have used Option Compare Text. But it seems like an elegant way to tell Excel VBA how to compare. I will be using it more often.
What about you? Do you use Option Compare? What are your favorite tips & tricks? Please share with us using comments.
More on Excel VBA
VBA (or Macros) is how you can tell Excel to automate parts of your work. It is a powerful programming language built right in to Excel (and other MS Office applications) to help you do more. If you are new to VBA, why don’t you go thru our Free crash course?
- Introduction to VBA & Excel Macros
- Understanding Variables, Conditions & Loops in VBA
- Using Cells, Ranges & Other Objects in your Macros
- Putting it all together – Your First VBA Application using Excel
- My Top 10 Tips for Mastering VBA & Excel Macros
Also, go thru our VBA (Macros) article collection for more tips, tutorials & ideas.

















7 Responses to “CP014: How to create awesome dashboards – 10 step process for you”
Very interested in topic unfortunately I get no sound when I play it.
Where can I get add ins for excel 2007
#Budala
Try using Google to search for Excel Addin
I would like to join your email newsletter.
@Andy
Goto: http://chandoo.org/wp/
The newletter registration is top Right corner
Hello Chandoo,
i am one of the great fan of your. i am one MIS executive in realstate company.And i try make dash board for CRM(Client Relation Management) Dept formance and anlysis process.Its get created not so effective according to can u suggest me .what i hve to give or take for makeing it for effective and attractive?.
regards,
Shashak verma
Hi,
I want to create an interactive dashboard in excel (Google Drive) which should have multiple data along with beautiful charts..
I handle two teams in IT Tech support so were preparing 2 different dashboards.. however need to club and want to create single report, can anyone help something like