11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

For i = 2 To TextLen<br />

If Mid(text, i, 1) = “ “ Then<br />

ACRONYM = ACRONYM & Mid(text, i + 1, 1)<br />

End If<br />

Next i<br />

ACRONYM = UCase(ACRONYM)<br />

End Function<br />

Chapter 25: VBA Custom Function Examples 687<br />

This function uses the Excel TRIM function to remove any extra spaces from the argument. The<br />

first character in the argument is always the first character in the result. The For-Next loop<br />

examines each character. If the character is a space, the character after the space is appended to<br />

the result. Finally, the result converts to uppercase by using the VBA UCase function.<br />

Does the text match a pattern?<br />

The following function returns TRUE if a string matches a pattern composed of text and wildcard<br />

characters. The ISLIKE function is remarkably simple, and is essentially a wrapper for the useful<br />

VBA Like operator.<br />

Function ISLIKE(text As String, pattern As String) As Boolean<br />

‘ Returns true if the first argument is like the second<br />

ISLIKE = text Like pattern<br />

End Function<br />

The supported wildcard characters are as follows:<br />

? Matches any single character<br />

* Matches zero or more characters<br />

# Matches any single digit (0–9)<br />

[list] Matches any single character in the list<br />

[!list] Matches any single character not in the list<br />

The following formula returns TRUE because the question mark (?) matches any single character.<br />

If the first argument were “Unit12”, the function would return FALSE.<br />

=ISLIKE(“Unit1”,”Unit?”)<br />

The function also works with values. The following formula, for example, returns TRUE if cell A1<br />

contains a value that begins with 1 and has exactly three numeric digits:<br />

=ISLIKE(A1,”1##”)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!