'Imagine the range as a rectangle.
'This crops it by the amounts specified and returns cropped range.
'Use negative numbers to expand the range
Public Function mCropRange(pRange As Range, pFromTop As Long, pFromLeft As Long, _
pFromBottom As Long, pFromRight As Long) As Range
Dim lNumRows As Long, lNumCols As Long
lNumCols = pRange.Columns.Count
lNumRows = pRange.Rows.Count
With pRange
Set mCropRange = Range(.Cells(1 + pFromTop, 1 + pFromLeft), _
.Cells(lNumRows - pFromBottom, lNumCols - pFromRight))
End With
End Function
?mCropRange(Range("B2:Y9"), -1, -1, -1, -1).Address
$A$1:$Z$10
?mCropRange(Range("A1:Z20"), 2, 2, 2, 2).Address
$C$3:$X$18
No comments:
Post a Comment