Microsoft Office Tutorials and References
In Depth Information
The Intersect method finds the cells representing the intersection of two ranges.
A popular use of the Intersect method is to determine if a cell selected by the user is within a
specific range. The TestPlants procedure prompts the user to select the largest monthly total
for Plants in the SalesByCategory.xls file and displays an error message if a cell is selected that
is not one of the monthly plant totals.
Dim strPrompt As String, rgePlants As Range, rgeIntersect As Range
strPrompt = "Please select the highest monthly total for Plants."
Set rgePlants = Application.InputBox(Prompt:=strPrompt, Title:=" Microsoft _
Office Excel 2003 Programming Inside Out", Type:=8)
Set rgeIntersect = Application.Intersect(Range("G2:G13"), rgePlants)
If rgeIntersect Is Nothing Then
strPrompt = "You did not select a Plant value".
MsgBox strPrompt, vbOKOnly + vbInformation
The OnKey method allows you to create hotkeys that will run a particular routine when
pressed or block Excel from behaving normally when the key combination is pressed. The
syntax for the OnKey method is