Sunday, 01 November 2009
OzGrid's Free Excel Newsletter
Microsoft Excel and VBA for Excel Training Information (auto response)
The newsletter is divided into four sections:
1. What's new at OzGrid.com
2. Microsoft Excel tips
3. Microsoft Excel VBA tips
4. Helpful information
It is published on about the 10th of each month and always written by myself Dave Hawley.
You are more than welcome to pass on this newsletter to as many people as you wish, all I ask is you pass it on in it's entirety.
Microsoft and Microsoft Excel are registered trademarks of Microsoft Corporation
Hi all
I hope all is well in all countries around the world at the moment, or at least as well as can be expected in light of recent world events. Recently my wife and I returned from an overseas trip to Bali, Indonesia and I don't mind telling you we were both a bit anxious about travelling to Indonesia. However, once there all our fears were soon dispelled as we were treated with the utmost respect and made to feel more than welcome. For those of you that are not familiar with Bali, it is a small Indonesian island that is extremely popular with Australians, both young and old. The cheap shopping there is a woman's dream come true and a husbands worst nightmare come true :o) All jokes aside though, the food and drink were fantastic, as were the people.
New Site
The biggest news for OzGrid this month is the imminent launch of our new Web site at www.ozgrid.com ! The site is now very near completion and should be finalized within a fortnight. At present www.microsoftexceltraining.com still points to our old site, but this should soon take you straight to www.ozgrid.com. If you haven't already, please browse around our new site and let us know what you think. While there, it would be great if you took five minutes to complete our training poll. This will enable us to better provide Microsoft Excel and VBA for Excel distance training and tutoring. A big thanks to all those that have taken the survey already!
I have also starting to send emails in HTML format (like this one) using stationary designed by Hans Stammel ofwww.avip.com.au. I have modified some of the HTML code supplied by Hans in this stationary, so if there are any problems at all it is most likely my fault, not Hans'! Should it get messed up on anyone's email program, please let me know.
Special Offer
As a special for the launch of our new site we will be offering a 20% discount off all Excel and VBA for Excel training courses for this month only - offer expires 10 December 2001 . These are normally AUD350.00, with the 20% discount this works out to AUD280.00. Convert this to US dollars and you are looking at about US150.00
You may also have noticed the Microsoft Excel and VBA for Excel Training Information (auto response) email link at the top of this newsletter, by clicking this link and sending the email generated, you will be sent an automated HTML email covering most of the details of our courses. You can also simply send an email to [email protected] and put the word TrainingInfo into the subject field.
Quick Survey
If you have a spare few minutes and as we now have our new web-site up and running, we would appreciate it if you would take 2 minutes and answer these 4 questions. All answers will be confidential.
I thought for this months Excel section I would share with you some of the answers I have supplied over the last month. These questions mainly come from people that have a nagging Excel problem they cannot solve. I am more than happy to try and supply answers to these questions, should my workload permit. I try to dedicate about 1 hour of each day to supplying answers to such questions, but as I've always said I must put my paying clients first. If you have sent me a question that has not been answered, please realize that I receive some 20 requests a day from people wanting help, and it is simply not possible to answer them all!
If you are part of an office team that uses Excel a lot you can benefit greatly by joining our help desk service. This will guarantee you will have an answer to your problems, if not you pay nothing! Let's face it, why spend hours trying (and often failing) to solve those Excel or VBA for Excel problems when we (OzGrid) probably know the answer. Please send me an email for full details.
One of the questions I answered this month was about having a Subtotal for 2 Columns of numbers. For those of you that received last month's newsletter, you may recall we looked at the SUBTOTAL function. I also suggested that you try the Subtotals... feature found under Data on the main menubar. For this instance though I suggested they try a very simple SUM formula. The reason I have included this in this months Newsletter is because (a) not only does it follow on well from last months newsletter and (b) it is also a great example of the right way and the wrong way to achieve something in Excel.
Let's suppose the 2 columns of numbers are in Columns "A" and "B" and cells A1 and B1 are headings. You could place this formula in cell C2 and copy down further than needed:
=IF(A2="","",SUM($A$1:B2))
This would certainly do the job, but is not a good method to use! To better understand why I will first show you the formula that should be used:
=IF(A2="","",SUM(A2:B2,C1))
Doesn't look much different really, does it? In fact there isn't much difference in the formula itself, but the first method is really very inefficient. To understand why, let's see what each formula looks like when copied down to say cell C1000
The formula would be placed in a cell like this:
=Find3XInaRow(0,$A$11:$H$11,$A$1:$H$1)
It's syntax is:
Find3XInaRow(xFindwhat,rLookin,rReturnFrom)
Comparing Text and Case Sensitivity
In last months newsletter I mentioned that I would show you how you can change Excel default way it compares text, (i.e Binary) which can make comparing text give unexpected results. Often when we compare text VBA code we are not interested in the case of the letters (i.e capital or lower).
To see what I mean type the word Cat (upper case "C") in cell A1 and then type cat (lower case "c") in cell A2. Now run this code:
Sub CompareText1()
If Range("A1").Text = Range("A2").Text Then
MsgBox True
Else
MsgBox False
End If
End Sub
You will get a False message box! This is because as far as Excel in concerned C <> c. Change both letter "c" to upper or lower and you get the True message box! What we need to do is force Excel to see C = c by using the Option Compare Statement at the *Module level.
Code placed in the Declarations section of a module. All code placed outside a procedure is module level code. Declarations must be listed first, followed by procedures.
So, to force Excel to see our 2 words (Cat and cat) as the same we simply use this:
Option Compare Text
Sub CompareText2()
If Range("A1").Text = Range("A2").Text Then
MsgBox True
Else
MsgBox False
End If
End Sub
It's that simple! Now to revert Excel back to it's default (Binary) we simply would use:
Option Compare Binary
Sub CompareText3()
If Range("A1").Text = Range("A2").Text Then
MsgBox True
Else
MsgBox False
End If
End Sub
Let's now take this text comparison one step further. Assume we want to compare text using wildcard characters. To do this we can use the Like statement. For this example we will see if the text in cell A1 contains the word cat. Type: The cat sat on the mat in cell A1, then run this code:
Sub CompareText4()
If Range("A1").Text Like ("*cat*") Then
MsgBox True
Else
MsgBox False
End If
End Sub
This will return True so long as you used a lower case "c" in A1 and the code! Even though we have used the Like statement it is (by default) still case sensitive. Unless of course you still have: Option Compare Text declared at the module level.
Naturally if A1 had the text cats are us! our message box would read False, because we have assumed there are characters before the word cat. To account for these sort of problems simply use:
Sub CompareText5()
If Range("A1").Text Like ("cat*") Or _
Range("A1").Text Like ("*cat") Or _
Range("A1").Text Like ("*cat*") Then
MsgBox True
Else
MsgBox False
End If
End Sub
Like the Select Case Statement we looked at in the last 2 newsletters, the Like Statement also automatically knows it's alphabet :o) To see what I mean by this type the single letter H in cell A1 then run both of these Procedures.
Sub CompareText6()
If Range("A1").Text Like "[A-I]" Then
MsgBox True
Else
MsgBox False
End If
End Sub
Sub CompareText7()
If Range("A1").Text Like "[A-G]" Then
MsgBox True
Else
MsgBox False
End If
End Sub
You should get True for Sub CompareText6() and False for Sub CompareText7().
Before I wind up this months newsletter, I would like to apologise to the person that sent me some nifty code for a Custom Function. I promised I would include it in this months newsletter, but I have lost the persons name. I didn't think it was fair to publish it without giving credit where credit is due. So if you could email again I will publish it in next months newsletter.
Until next month, keep Excelling!
Kind regards
Dave Hawley
Helpful Information