SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 102 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

The DataRegionStart property sets and returns the cell that begins our
data region. This is used when we clear the sheet at the start of our procedures and when we
perform our autofit during cleanup.
Even though we??™ve got Property Get and Set functions for these two properties, we??™re
going to create an initialization function that allows us to set them both at once. This give us
the advantage of using less client code to accomplish the task of setting two properties, yet
gives us the flexibility of using the property settings directly if we need to.
Public Sub SetKeyCells(InitialCell As Range, DataRegionStart As Range)
Set m_rngInitialCellSelect = InitialCell
Set m_rngDataRegionStart = DataRegionStart
End Sub
CHAPTER 2 n DATA IN, DATA OUT 89
Now that we??™ve got our key properties laid out, we can concentrate on adding our setup
and cleanup code.
Add a new subroutine called SetupWorksheet, and add the following code:
Public Sub SetupWorksheet()
Me.Worksheet.Activate
ClearRegion
Me.InitialCellSelection.Select
End Sub
This code corresponds to our original code from our standard module:
Set xlSheet = Sheets("Sheet2")
xlSheet.Activate
Range("A1").Activate
Selection.CurrentRegion.Select
Selection.ClearContents
Range("A1").Select
The first and last lines of the SetupWorksheet routine correspond to the first and last lines
of our original code. There is a call to a private method called ClearRegion that does the work
of the remaining original code:
Private Sub ClearRegion()
m_xlSheet.


Pages:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114