Tuesday 16 April 2019

VBA Excel: Extending & Shortening Cell Range

'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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...