Hello,
I've been doing some reading recently and many people are saying the same thing with regards to putting code in a worksheet - "Declare only events in a worksheet, nothing more". The statement in itself isn't that crazy, but it makes me ponder if it's a hard set rule of if there are exceptions?
For instance, should a property or constant that applies exclusively to a particular worksheet still be declared in a module or would it be better to leave it in the worksheet? Moreover if I'm not declaring it in the worksheet, shouldn't it be in a class module instead of a basic module? A benefit of leaving code in the worksheet is it opens up to the "me." keyword. With this the user never needs worry if a worksheet codename is changed and it localizes it to the object reference.
Don't get me wrong I'm not trying to argue one way or another, but I ask this question because that is currently how I have some code setup and I can't help but wonder if I should move it to a module for overall more manageable code. Thoughts?
Example:
Worksheet:
Module "mInitialize:
Module "mUtility:
I've been doing some reading recently and many people are saying the same thing with regards to putting code in a worksheet - "Declare only events in a worksheet, nothing more". The statement in itself isn't that crazy, but it makes me ponder if it's a hard set rule of if there are exceptions?
For instance, should a property or constant that applies exclusively to a particular worksheet still be declared in a module or would it be better to leave it in the worksheet? Moreover if I'm not declaring it in the worksheet, shouldn't it be in a class module instead of a basic module? A benefit of leaving code in the worksheet is it opens up to the "me." keyword. With this the user never needs worry if a worksheet codename is changed and it localizes it to the object reference.
Don't get me wrong I'm not trying to argue one way or another, but I ask this question because that is currently how I have some code setup and I can't help but wonder if I should move it to a module for overall more manageable code. Thoughts?
Example:
Worksheet:
VBA Code:
Const intSide1Length As String = "E46"
Property Get Side1Length()
Side1Length = Me.Range(intSide1Length).Value
End Property
Property Let Side1Length(intSide1LengthValue)
Me.Range(intSide1Length).Value = intSide1LengthValue
End Property
Module "mInitialize:
VBA Code:
mUtility.RoundUp((mUtility.FootToInch(Sheet1.Side1Length)
Module "mUtility:
VBA Code:
Function RoundUp(Number As Double, Digit As Double)
'Rounds Number up to decimal place indicated in Digit.
'ROUND UP VALUE(S):
RoundUp = Application.WorksheetFunction.RoundUp(Number, Digit)
End Function