WasteNot Excel VBA Library Module LM3 Documentation
Range
RaC > Info >
IsVal
IsVal (
iRa As Variant )
As Boolean
'180000a
Succeeds if iRa is a Valid Range Object ie contains 1
or more Cells
RaC > Info >
IsValEx
IsValEx (
iRa As Variant,
ouAdd As String, _
Default ouAdd Format is Local, xlR1C1 (=-4150) eg R1:R1048576
If iExt is SetOn, ouAdd is External eg [WbNa.xlsm]WsNa!R1:R1048576
The alternative iRefStyle is xlA1 (=1) eg '[WbNa.xlsm]Ws Na'!$1:$1048576
See Code Notes > Range Address Ambiguity
and > External Range Addresses Anomaly
Optional iExt As Boolean, _
Optional iRefStyle As XlReferenceStyle = xlR1C1 ) As Boolean '191003b
Succeeds, an Sets ouAdd, if iRa is a Range Object containing 1 or more Cells Optional iRefStyle As XlReferenceStyle = xlR1C1 ) As Boolean '191003b
Default ouAdd Format is Local, xlR1C1 (=-4150) eg R1:R1048576
If iExt is SetOn, ouAdd is External eg [WbNa.xlsm]WsNa!R1:R1048576
The alternative iRefStyle is xlA1 (=1) eg '[WbNa.xlsm]Ws Na'!$1:$1048576
See Code Notes > Range Address Ambiguity
and > External Range Addresses Anomaly
RaC > Info >
AddOf
AddOf (
iRa As Variant,
Optional iExt As Boolean, _
See also IsValEx
Optional iRefStyle As XlReferenceStyle = xlR1C1 )
As String
'191003c
Returns the Address of iRa if it is a Range Object
containing 1 or more Cells, or the Null String if it is Not See also IsValEx
RaC > Info >
IsValAdd
IsValAdd (
iAdd As String,
Optional oRa As Range )
As Boolean
'190829a
Succeeds, and sets oRa, if iAdd is a Valid Range Address in an Open Workbook
iAdd may be in any Case, and may be Untrimmed, but refer to the following Code Notes
- "Range Address Formats" ,
- "Range Address Ambiguity" and
- "External Range Addresses Anomaly"
- "Cell Values with a Leading Apostrophe (aka Single Quote)"
egs " '[(WNXlA_123.XlA]Cb'!R1C1", "$A$1", "A1", "A1:B2", "R2C2:R3C3","$1:$1"
iAdd may be in any Case, and may be Untrimmed, but refer to the following Code Notes
- "Range Address Formats" ,
- "Range Address Ambiguity" and
- "External Range Addresses Anomaly"
- "Cell Values with a Leading Apostrophe (aka Single Quote)"
egs " '[(WNXlA_123.XlA]Cb'!R1C1", "$A$1", "A1", "A1:B2", "R2C2:R3C3","$1:$1"
RaC > Info >
LongCeCou
LongCeCou (
iRa As Variant,
Optional oOvfl As Boolean, _
oOvfl is Set if iRa contains > 2.147483647 Billion Cells, and in this case
the Default Return is 2,147,483,647 unless iRet0ForOvfl is Set, in which case the Return is 0
Optional iRet0ForOvfl As Boolean )
As Long
'180000e
Returns the No. of Cells in iRa, as a Long Value, or
0 if iRa is Not a Range Object oOvfl is Set if iRa contains > 2.147483647 Billion Cells, and in this case
the Default Return is 2,147,483,647 unless iRet0ForOvfl is Set, in which case the Return is 0
RaC > Info >
LargeCeCou
LargeCeCou (
iRa As Variant )
As Variant
'180000f
Returns the No. of Cells in iRa, as a LongLong Value,
or 0 if iRa is Not a Range Object
eg LargeCeCou(Activesheet) = 17.179869184 Billion
eg LargeCeCou(Activesheet) = 17.179869184 Billion
RaC > Info >
HasData
HasData (
iRa As Variant,
Optional oaIsValRa As Boolean, _
A Blank or Empty Cell has a Null Value and a Null Formula
Empty Cells with Borders, Interior Colors &/Or Comments count as Blank
oaIsValRa is SetOn if iRa is a Valid Range
ocNODataCes is the No. of Data Cells in iRa
Optional ocNODataCes As Variant )
As Boolean
'191003a
Succeeds if iRa is a Valid Range that Contains Data,
ie Cells that are Not Blank A Blank or Empty Cell has a Null Value and a Null Formula
Empty Cells with Borders, Interior Colors &/Or Comments count as Blank
oaIsValRa is SetOn if iRa is a Valid Range
ocNODataCes is the No. of Data Cells in iRa
RaC > Return >
we_RaToSA
Range To String Array conversion mode
Enumeration
`161100f Rac.RaToSA()
we_rts1ByRs
we_rts1ByCs
we_rts2ByRs
we_rts2ByCs
1D by Rows
Default 2D by Rows
we_rts1ByCs
we_rts2ByRs
we_rts2ByCs
1D by Rows
Default 2D by Rows
RaC > Return >
RaToSA
RaToSA (
iRa As Range,
oSA() As String, _
Fails if iRa is Not a Valid Range
By default oSA is a 2D Array of Dimensions (1 to iRa.Rows.Count, 1 to iRa.Columns.Count)
Other Structures may be specified using
iConvSpec to change the No.of Dimensions and Conversion Order (see we_RaToSA) and/or
iSaD1LB & iSaD2LB to set oSA's Dim 1 and/or Dim 2 Lower Bound(s)
oSaD1 & oSaD2 return oSA's Dimensions
egs iRa.Rows.Count & iRa.Columns.Count for the Default Case
iRa.Rows.Count * iRa.Columns.Count & 0 for 1D Cases
NOTE a Simpler Method is to Fill a Variant Array with a single Statement
eg Dim VarA() As Variant
VarA = iRa
But
1) VarA's Type MUST be Variant
2) it will be 1-Based by Rows
3) a RTE occurs if iRa is a Single Cell
see Code Notes "Arrays as Parameters" and "Arrays and Ranges"
Optional iConvSpec As we_RaToSA = we_rts2ByRs, _
Optional iSaD1LB As Long = 1, Optional iSaD2LB As Long = 1, _
Optional oSaD1 As Long, Optional oSaD2 As Long ) As Boolean '181026a
Returns a String Array (oSA) of iRa's ValuesOptional iSaD1LB As Long = 1, Optional iSaD2LB As Long = 1, _
Optional oSaD1 As Long, Optional oSaD2 As Long ) As Boolean '181026a
Fails if iRa is Not a Valid Range
By default oSA is a 2D Array of Dimensions (1 to iRa.Rows.Count, 1 to iRa.Columns.Count)
Other Structures may be specified using
iConvSpec to change the No.of Dimensions and Conversion Order (see we_RaToSA) and/or
iSaD1LB & iSaD2LB to set oSA's Dim 1 and/or Dim 2 Lower Bound(s)
oSaD1 & oSaD2 return oSA's Dimensions
egs iRa.Rows.Count & iRa.Columns.Count for the Default Case
iRa.Rows.Count * iRa.Columns.Count & 0 for 1D Cases
NOTE a Simpler Method is to Fill a Variant Array with a single Statement
eg Dim VarA() As Variant
VarA = iRa
But
1) VarA's Type MUST be Variant
2) it will be 1-Based by Rows
3) a RTE occurs if iRa is a Single Cell
see Code Notes "Arrays as Parameters" and "Arrays and Ranges"
RaC > Return >
IntOrUnion
IntOrUnion (
ByVal ivRa1 As Variant,
ByVal ivRa2 As Variant,
Optional ocRa As Range, _
Fails, and Sets ocRa to Nothing, if
1. Either ivRa is Not of Range Type
2. Both Range's are Not Nothing, and are Not in the Same WS
3. ocRa is Nothing
egs Intersection when Either ivRa is Nothing
Union when Both ivRa's are Nothing
VB's Intersect and Union Functions cause a Runtime Error for Cases 1 & 2,
or Any Range Argument is Nothing
Optional iRetUnion As Boolean )
As Boolean
'191003d
Sets ocRa to the Intersection, (or Union if iRetUnion is True) , of ivRa1 &
ivRa2 Fails, and Sets ocRa to Nothing, if
1. Either ivRa is Not of Range Type
2. Both Range's are Not Nothing, and are Not in the Same WS
3. ocRa is Nothing
egs Intersection when Either ivRa is Nothing
Union when Both ivRa's are Nothing
VB's Intersect and Union Functions cause a Runtime Error for Cases 1 & 2,
or Any Range Argument is Nothing
RaC > Return >
Unify
Unify (
iRa As Variant )
As Range
'190928a
Returns the Unification of iRa; the Smallest Single
Area that Encloses All iRa's Areas
RaC > Return >
ExclA1
ExclA1 (
ByVal ivExclRa As Range )
As Range
'181106a
Returns ivExclRa, Excluding Area(1) of ivExclRa
Returns Nothing if ivExclRa is Nothing, or an Entire Worksheet's Cells
The Return is known as the Complement or Difference of these two Ranges
Returns Nothing if ivExclRa is Nothing, or an Entire Worksheet's Cells
The Return is known as the Complement or Difference of these two Ranges
RaC > Return >
Excl
Excl (
ByVal ivExclRa As Range,
ByVal ivEFRa As Range )
As Range
'191003e
Returns ivEFRa, Excluding ivExclRa
Works with Mult-Area Ranges (MARs)
Returns ivEFRa if iExlcRa is Nothing
Returns Nothing if
ivExclRa and ivEFRa are from Different WSs Or
ivEFRa is Nothing
The Return is known as the Complement or Difference of these two Ranges
Works with Mult-Area Ranges (MARs)
Returns ivEFRa if iExlcRa is Nothing
Returns Nothing if
ivExclRa and ivEFRa are from Different WSs Or
ivEFRa is Nothing
The Return is known as the Complement or Difference of these two Ranges
RaC > Return >
wResize
wResize (
iRa As Variant,
Optional iIncrease As Boolean = True, _
Returns Nothing if iRa is Not a Valid Range
iIncrease determines if iRa's Size is Increased or Decreased
If ivRs is +ve, iRa's size is changed from it's Last Row
If ivRs is -ve, iRa's size is changed from it's First Row
If ivRs is Omitted, or 0, the NO Rows is Unchanged
ivCs determines the NO of Columns in a simlar manner
Attempting to Increase iRa's Size beyond the Worksheet's Boundaries
works, but the Return will be "Trimmed" to the Boundary
(ie <ivRs Rows and/or <ivCs bigger)
Attempting to Decrease iRa's Size to <1 Row or Column
Returns Nothing
egs if iRa = R2C2 then
Increasing 0R, 1C -> R2C2:R2C3
Increasing 1R, -1C -> R2C1:R3C2
Increasing 1R, -2C -> same
if iRa = C2 then
Increasing 1R, 0C -> C2
If iRa = R1C2:R1C3 Then
Decreasing 0R, -1C -> R1C3
Decreasing 1R, 0C -> Nothing
Optional ByVal ivRs As Long,
Optional ByVal ivCs As Long )
As Range
'190911a
Resizes iRa by ivRs Rows
and ivCs Columns Returns Nothing if iRa is Not a Valid Range
iIncrease determines if iRa's Size is Increased or Decreased
If ivRs is +ve, iRa's size is changed from it's Last Row
If ivRs is -ve, iRa's size is changed from it's First Row
If ivRs is Omitted, or 0, the NO Rows is Unchanged
ivCs determines the NO of Columns in a simlar manner
Attempting to Increase iRa's Size beyond the Worksheet's Boundaries
works, but the Return will be "Trimmed" to the Boundary
(ie <ivRs Rows and/or <ivCs bigger)
Attempting to Decrease iRa's Size to <1 Row or Column
Returns Nothing
egs if iRa = R2C2 then
Increasing 0R, 1C -> R2C2:R2C3
Increasing 1R, -1C -> R2C1:R3C2
Increasing 1R, -2C -> same
if iRa = C2 then
Increasing 1R, 0C -> C2
If iRa = R1C2:R1C3 Then
Decreasing 0R, -1C -> R1C3
Decreasing 1R, 0C -> Nothing
RaC > Return >
we_Dir
Directions
Enumeration
`190925a RaC.AdjRa()
we_dirNone
we_dirOri
we_dirComplM
we_dirCardM
we_dirUp
we_dirRight
we_dirDown
we_dirLeft
we_dirN
we_dirE
we_dirS
we_dirW
we_dirNScc
we_dirEWcc
we_dirIntM
we_dirNE
we_dirSE
we_dirSW
we_dirNW
we_dirEci
we_dirWci
we_dirNcm
we_dirEcm
we_dirScm
we_dirWcm
we_dirNoNcm
we_dirNoEcm
we_dirNoScm
we_dirNoWcm
we_dirNorEcm
we_dirEorScm
we_dirSorWcm
we_dirWorNcm
we_dirNoNorEcm
we_dirNoEorScm
we_dirNoSorWcm
we_dirNoWorNcm
Origin, Home or Centre
Directions are Relative to this entity
Complimentary (Components) Mask
All 9 Components Outside the Origin
(9Cs -> 4 Areas)
Cardinal (Components) Mask
(1C -> 1 Area)
Combined Cardinal (Components)
(2Cs -> 2 Areas)
Intercardinal (Components) Mask
(1C -> 1 Area)
Combined Intercardinal (Components)
(2Cs -> 2 Areas)
Combined & Mixed(Cardinal & Intercardinal Components)
N + NE + NW'Any Northerly (3Cs -> 1 Area)
E + NE + SE'E
S + SE + SW'S
W + SW + NW'W
E + SC + W'No Northerly (5Cs -> 3 Areas)
N + S + WC ' E
NC + E + W' S
N + EC + S' W
NC + EC'Any Northerly Or Easterly (5Cs -> 2 Areas)
EC + SC'ES
SC + WC'SW
WC + NC'WN
S + SW + W 'No Northerly Or Easterly (3Cs -> 2 Areas)
W + NW + N ' ES
N + NE + E ' SW
E + SE + S ' WN
we_dirOri
we_dirComplM
we_dirCardM
we_dirUp
we_dirRight
we_dirDown
we_dirLeft
we_dirN
we_dirE
we_dirS
we_dirW
we_dirNScc
we_dirEWcc
we_dirIntM
we_dirNE
we_dirSE
we_dirSW
we_dirNW
we_dirEci
we_dirWci
we_dirNcm
we_dirEcm
we_dirScm
we_dirWcm
we_dirNoNcm
we_dirNoEcm
we_dirNoScm
we_dirNoWcm
we_dirNorEcm
we_dirEorScm
we_dirSorWcm
we_dirWorNcm
we_dirNoNorEcm
we_dirNoEorScm
we_dirNoSorWcm
we_dirNoWorNcm
Origin, Home or Centre
Directions are Relative to this entity
Complimentary (Components) Mask
All 9 Components Outside the Origin
(9Cs -> 4 Areas)
Cardinal (Components) Mask
(1C -> 1 Area)
Combined Cardinal (Components)
(2Cs -> 2 Areas)
Intercardinal (Components) Mask
(1C -> 1 Area)
Combined Intercardinal (Components)
(2Cs -> 2 Areas)
Combined & Mixed(Cardinal & Intercardinal Components)
N + NE + NW'Any Northerly (3Cs -> 1 Area)
E + NE + SE'E
S + SE + SW'S
W + SW + NW'W
E + SC + W'No Northerly (5Cs -> 3 Areas)
N + S + WC ' E
NC + E + W' S
N + EC + S' W
NC + EC'Any Northerly Or Easterly (5Cs -> 2 Areas)
EC + SC'ES
SC + WC'SW
WC + NC'WN
S + SW + W 'No Northerly Or Easterly (3Cs -> 2 Areas)
W + NW + N ' ES
N + NE + E ' SW
E + SE + S ' WN
RaC > Return >
AdjRa
AdjRa (
ByVal ivRa As Variant,
iDir As we_Dir,
Optional ocRa As Range,
Optional oNullComps As we_Dir )
As Boolean
'190924a
If Successful, Returns ocRa; the Adjacent Range to
ivRa.Areas(1) in the Direction of iDir
Fails if ivRa Or ocRa is Nothing
ocRa is bounded by the ivRa's Worksheet Boundaries
Including we_dirOri as part of iDir causes ivRa to be included in ocRa and
Setting iDir=we_dirComplM returns the Compliment of (or Range OutSide) ivRa, so
Setting iDir=we_dirComplM + we_dirOri returns ocRa as ivRa.Parent.Cells
oNullComps returns all the Null Component Ranges of ocRa
If ivRa doesn't touch a Worksheet Boundary, then ocValComp=0
ocRa's Component Areas are Unsorted (see RaC.SortAreas)
Fails if ivRa Or ocRa is Nothing
ocRa is bounded by the ivRa's Worksheet Boundaries
Including we_dirOri as part of iDir causes ivRa to be included in ocRa and
Setting iDir=we_dirComplM returns the Compliment of (or Range OutSide) ivRa, so
Setting iDir=we_dirComplM + we_dirOri returns ocRa as ivRa.Parent.Cells
oNullComps returns all the Null Component Ranges of ocRa
If ivRa doesn't touch a Worksheet Boundary, then ocValComp=0
ocRa's Component Areas are Unsorted (see RaC.SortAreas)
RaC > Return >
we_UsedRaOs
UsedRange Options
Enumeration
`190927a RaC.UsedRa()
we_urVB
we_urData
we_urShas
we_urAny
we_urLastCeOnly
we_urLastVBCe
IncludeVB UsedRange
" Data (Using Find("*"))
" Shape Objects
we_urData
we_urShas
we_urAny
we_urLastCeOnly
we_urLastVBCe
IncludeVB UsedRange
" Data (Using Find("*"))
" Shape Objects
RaC > Return >
UsedRa
UsedRa (
iWs As Worksheet,
Optional iUROpts As we_UsedRaOs = we_urVB,
Optional iExtDir As we_Dir )
As Range
'190927b
By Default, Returns iWS's Used Range, or Nothing if iWS Doesn't Exist
Refer to Code Notes > The Worksheet UsedRange, and Note that a Blank Worksheet's UsedRange is R1C1
The Default Return is the same as iWs.UsedRange, but
iUROpts may be used to
to Exclude or Include
the UsedRange and/or
the Range Containing Data (Values or Formulae) and/or
Shape Objects or
to Return only the Last Cell of what it would otherwise have been and
iExtDir may be used to
Extend it to include Adjacent Ranges (see RaC.AdjRan)
Refer to Code Notes > The Worksheet UsedRange, and Note that a Blank Worksheet's UsedRange is R1C1
The Default Return is the same as iWs.UsedRange, but
iUROpts may be used to
to Exclude or Include
the UsedRange and/or
the Range Containing Data (Values or Formulae) and/or
Shape Objects or
to Return only the Last Cell of what it would otherwise have been and
iExtDir may be used to
Extend it to include Adjacent Ranges (see RaC.AdjRan)
RaC > Return >
we_RaBou
Range Boundaries
Enumeration
`161100i RaC.WsBouCe()
we_rbmCor
we_rbmCR
we_rbcTL
we_rbcTR
we_rbcBR
we_rbcBL
we_rbmUR
we_rbuTL
we_rbuTR
we_rbuBR
we_rbuBL
we_rbmWS
we_rbwTL
we_rbwTR
we_rbwBR
we_rbwBL
we_rbmSea
we_rbmSCor
we_rbmDir
we_rbmOrd
we_rbdTL
we_rbdTR
we_rbdRT
we_rbdRB
we_rbdBR
we_rbdBL
we_rbdLB
we_rbdLT
Corners Mask
CurrentRegion Corners Mask
Top-Left
Top-Right
Bottom-Right
Bottom-Left
UsedRange Corners Mask
Worksheet Corners Mask
Data Search Mask
Search from Corner Mask1=TL ... 8=BR
Search Direction Mask1=Next, 2=Prev
" Order " 1=ByRows, 2=ByCols
Top-Left
Top-Right
Right-Top
Right-Bottom
Bottom-Right
Bottom-Left
Left-Bottom
Left-Top
we_rbmCR
we_rbcTL
we_rbcTR
we_rbcBR
we_rbcBL
we_rbmUR
we_rbuTL
we_rbuTR
we_rbuBR
we_rbuBL
we_rbmWS
we_rbwTL
we_rbwTR
we_rbwBR
we_rbwBL
we_rbmSea
we_rbmSCor
we_rbmDir
we_rbmOrd
we_rbdTL
we_rbdTR
we_rbdRT
we_rbdRB
we_rbdBR
we_rbdBL
we_rbdLB
we_rbdLT
Corners Mask
CurrentRegion Corners Mask
Top-Left
Top-Right
Bottom-Right
Bottom-Left
UsedRange Corners Mask
Worksheet Corners Mask
Data Search Mask
Search from Corner Mask1=TL ... 8=BR
Search Direction Mask1=Next, 2=Prev
" Order " 1=ByRows, 2=ByCols
Top-Left
Top-Right
Right-Top
Right-Bottom
Bottom-Right
Bottom-Left
Left-Bottom
Left-Top
RaC > Return >
WsBouCe
WsBouCe (
iWhich As we_RaBou,
Optional iWs As Worksheet )
As Range
'181030a
Returns the Boundary Cell specified by iWhich in
Worksheet iWs
Returns Nothing if you try to Return a Data Cell from a Blank Range
iWhich specifies one of iWs's 12 Corner or 8 Data Cells, defined in the we_RaBou Enumeration
iWs Defaults to the Activesheet
To return a Corner Cell, set iWhich to one of the 12 Corner Cell Mask Bits
eg WsBouCe(we_rbuBR) returns the Bottom-Right Corner Cell of the Activesheet's UsedRange
To return a Data Cell, set iWhich to the Sum of the Top-Left Corner Cell Mask Bit and the desired Data Cell Mask
eg WsBouCe(we_rbuTL + we_rbdLB = &H10 + &H822000 = &H822010) returns the Left-Bottom Data Cell in the UsedRange
Notes 1) Using iWhich Values other than those specified may cause a RTE
2) Worksheet and UsedRange Data Cells are the Same
3) Returns R1C1 for all Corners of a Blank Worksheet
Returns Nothing if you try to Return a Data Cell from a Blank Range
iWhich specifies one of iWs's 12 Corner or 8 Data Cells, defined in the we_RaBou Enumeration
iWs Defaults to the Activesheet
To return a Corner Cell, set iWhich to one of the 12 Corner Cell Mask Bits
eg WsBouCe(we_rbuBR) returns the Bottom-Right Corner Cell of the Activesheet's UsedRange
To return a Data Cell, set iWhich to the Sum of the Top-Left Corner Cell Mask Bit and the desired Data Cell Mask
eg WsBouCe(we_rbuTL + we_rbdLB = &H10 + &H822000 = &H822010) returns the Left-Bottom Data Cell in the UsedRange
Notes 1) Using iWhich Values other than those specified may cause a RTE
2) Worksheet and UsedRange Data Cells are the Same
3) Returns R1C1 for all Corners of a Blank Worksheet
RaC > Return >
GetWSSel
GetWSSel (
iWs As Worksheet )
As Range
'190829b
Returns iWs's currently Selected Range
Returns Nothing if iWs is not a Valid Worksheet, or it's Selection is Not a Range
This is done by Invisibly Selecting iWs, and then Reselecting the Original ActiveSheet
Returns Nothing if iWs is not a Valid Worksheet, or it's Selection is Not a Range
This is done by Invisibly Selecting iWs, and then Reselecting the Original ActiveSheet
RaC > Activate >
wSel
wSel (
iRa As Range )
As Boolean
'181101a
Selects iRa, the same as if the User had Selected it
Fails if iRa is not a Valid Range
See also CodeNotes > Difference Between Select and Activate
Fails if iRa is not a Valid Range
See also CodeNotes > Difference Between Select and Activate
RaC > Activate >
wChaWSSel
wChaWSSel (
iRa As Range )
As Boolean
'181101b
Invisibly Selects iRa in it's Parent Worksheet, and
then Reselects the Original Selection
Fails if iRa is not a Valid Range
If iRa is in the ActiveSheet, the net effect is nothing
Fails if iRa is not a Valid Range
If iRa is in the ActiveSheet, the net effect is nothing
RaC > Sort >
SortEntRs
SortEntRs (
ByVal ivKeyRa As Range, _
ie Each Row in ivKeyRa is Preserved as is, but the Order of these Rows will usually change
Fails if ivKeyRa is Nothing or contains More Than 3 Key Columns
ivKeyRa may consist of up to 3 Key Columns, and the Sort Precedence is the Order in which
these columns are Selected/Addressed
If the Key Columns contain different No.s of Rows, the First Key Range sets the No. of Rows Sorted
(ie you only need to specify a single Cell of the 2nd & 3rd Key Columns)
Setting iRev Reverses the Sort Order
The default Data Type Order (iDTOrd = xlSortTextAsNumbers) treats Numeric Text the same as Numeric Data
Setting it to xlSortNormal causes the Numeric Data to be Sorted before Text Data
See CodeNotes > Data and Range Formats
iRev and iDTOrd are applied to All Key Ranges
Note an Exception: Blank Cells Always get Sorted to the Bottom of ivKeyRa, in their Original Order
eg1 Default SortEntRs with ivKeyRa Set to Column 1 then Column 2
(Blank) 2 1 R1
a * R3 => 2 z R2
2 z R a * R3
2 1 R1 (Blank)
(for Numeric Or Text Data)
eg2 Default with Numeric Or Text Data
10 => 9 but => 10 with Text Data and iDTOrd Set to xlSortNormal
9 10 9 (or if "10" is Numeric and "9" is Text)
Optional iRev As Boolean, _
Optional iDTOrd As XlSortDataOption = xlSortTextAsNumbers ) As Boolean '181108a
Sorts the EntireRows of ivKeyRa, into the Order
determined by ivKeyRa's Column Values Optional iDTOrd As XlSortDataOption = xlSortTextAsNumbers ) As Boolean '181108a
ie Each Row in ivKeyRa is Preserved as is, but the Order of these Rows will usually change
Fails if ivKeyRa is Nothing or contains More Than 3 Key Columns
ivKeyRa may consist of up to 3 Key Columns, and the Sort Precedence is the Order in which
these columns are Selected/Addressed
If the Key Columns contain different No.s of Rows, the First Key Range sets the No. of Rows Sorted
(ie you only need to specify a single Cell of the 2nd & 3rd Key Columns)
Setting iRev Reverses the Sort Order
The default Data Type Order (iDTOrd = xlSortTextAsNumbers) treats Numeric Text the same as Numeric Data
Setting it to xlSortNormal causes the Numeric Data to be Sorted before Text Data
See CodeNotes > Data and Range Formats
iRev and iDTOrd are applied to All Key Ranges
Note an Exception: Blank Cells Always get Sorted to the Bottom of ivKeyRa, in their Original Order
eg1 Default SortEntRs with ivKeyRa Set to Column 1 then Column 2
(Blank) 2 1 R1
a * R3 => 2 z R2
2 z R a * R3
2 1 R1 (Blank)
(for Numeric Or Text Data)
eg2 Default with Numeric Or Text Data
10 => 9 but => 10 with Text Data and iDTOrd Set to xlSortNormal
9 10 9 (or if "10" is Numeric and "9" is Text)
RaC > Sort >
SortERsByColr
SortERsByColr (
ByVal ivRa As Range,
Optional iRev As Boolean, _
ie Each Row in ivRa is Preserved as is, but the Order of these Rows will usually change
If ivRa is more than 1 Column Wide, Cells in it's First Column determine the Sort Order
If ivRa extends Outside the Sheet's UsedRange, only the part that lies Within the UsedRange is Sorted
Setting iRev Reverses the Order of the Sorted Blocks
ivOptStr may be set to
1. "Def" or "Def [Color] [CSV]" (the Default)
2. "Color"
3. a Comma-Separated String of Numerical Color Value(s)to Match
egs "&HFF,&HFF00,&HFF0000" or
"255,65280,16711680" for Red, Green and Blue
Other values of ivOptStr will cause unpredictable results, and may cause a RTE
Options 1 and 2 Sort All ivRa's Rows into Blocks of the Same Color
For Option 1 the Blocks are arranged in the order in which they Originally Occured in ivRa
eg if the Top Cell in ivRa is Red, and the 2nd is Green
all Red Cells are Sorted into the Top Block,
all Green Cells are Sorted into the 2nd Block, and so on
For Option 2 the Blocks are arranged in Ascending RGB Color
eg Black (&H0) ... Red (&HFF) ... Green (&HFF00) ... Blue (&HFF0000) ... White (&HFFFFFF)
Option 3 Sorts only the Colors specified in the CSV String to the Top of ivRa in Blocks of the Same Color,
in the same order in which the occur in the CSV.
Cells that do not match any color in the CSV remain Unsorted in a Block at the Bottom of ivRa
SortERsByColr Returns the No. of Sorted Rows, which will be
= 0 if ivRa is Nothing
= ivRa.Rows.Count for Options 1 & 2
<= ivRa.Rows.Count for Option 3
Optional ByVal ivOptStr As String = "Def [Color] [CSV]" )
As Long
'190831a
Sorts the EntireRows of ivRa into Blocks, according
to the (Interior) Color of ivRa's Cells ie Each Row in ivRa is Preserved as is, but the Order of these Rows will usually change
If ivRa is more than 1 Column Wide, Cells in it's First Column determine the Sort Order
If ivRa extends Outside the Sheet's UsedRange, only the part that lies Within the UsedRange is Sorted
Setting iRev Reverses the Order of the Sorted Blocks
ivOptStr may be set to
1. "Def" or "Def [Color] [CSV]" (the Default)
2. "Color"
3. a Comma-Separated String of Numerical Color Value(s)to Match
egs "&HFF,&HFF00,&HFF0000" or
"255,65280,16711680" for Red, Green and Blue
Other values of ivOptStr will cause unpredictable results, and may cause a RTE
Options 1 and 2 Sort All ivRa's Rows into Blocks of the Same Color
For Option 1 the Blocks are arranged in the order in which they Originally Occured in ivRa
eg if the Top Cell in ivRa is Red, and the 2nd is Green
all Red Cells are Sorted into the Top Block,
all Green Cells are Sorted into the 2nd Block, and so on
For Option 2 the Blocks are arranged in Ascending RGB Color
eg Black (&H0) ... Red (&HFF) ... Green (&HFF00) ... Blue (&HFF0000) ... White (&HFFFFFF)
Option 3 Sorts only the Colors specified in the CSV String to the Top of ivRa in Blocks of the Same Color,
in the same order in which the occur in the CSV.
Cells that do not match any color in the CSV remain Unsorted in a Block at the Bottom of ivRa
SortERsByColr Returns the No. of Sorted Rows, which will be
= 0 if ivRa is Nothing
= ivRa.Rows.Count for Options 1 & 2
<= ivRa.Rows.Count for Option 3
RaC > Sort >
SortByTLC
SortByTLC (
ByVal ivRa As Range,
Optional iRev As Boolean,
Optional iLtDShadeM As Long = &H1C )
As Long
'190829c
Sort by Traffic Light Colors
Similar to SortERsByColr(), but the Sorted Rows are arranged in "Traffic Light Order"
From Top to Bottom the Default Sorted Order is in Groups
Group Color Shade iLtDShadeM
Sort Bit
Order
0. (White)
1. Red D>L &H1
2. Orange D>L &H2
3. Green L>D &H4
4. (Blue) L>D &H8
5. (Grey/Black) L>D &H10
from either Darkest to Lightest (D>L) Or
Lightest to Darkest (L>D) within each Group
The Logic for this Sort order is somewhat "Fuzzy";
- White, Black and Greys must have equal RG and B Components
- Colors without strong Primary Components will usually sort into the Orange Group
iRev Reverses the Sorted Order Completely
eg Black > Dark Grey ... > Dark Red > White for Default iLtDShadeM
The Shade Mask, iLtDShadeM, may be used to Control the Sort Order of Shades within each Group
Setting a Group's Bit in iLtDShadeM to 1 causes that Group to be Sorted in Light to Dark Order (if iRev is False)
eg the Default Value of (&H4 + &H8 + &H10 =) &H1C causes
Groups 1 & 2 to be Sorted D>L (0's in iLtDShadeM)
Groups 3 to 5 to be Sorted L>D
Similar to SortERsByColr(), but the Sorted Rows are arranged in "Traffic Light Order"
From Top to Bottom the Default Sorted Order is in Groups
Group Color Shade iLtDShadeM
Sort Bit
Order
0. (White)
1. Red D>L &H1
2. Orange D>L &H2
3. Green L>D &H4
4. (Blue) L>D &H8
5. (Grey/Black) L>D &H10
from either Darkest to Lightest (D>L) Or
Lightest to Darkest (L>D) within each Group
The Logic for this Sort order is somewhat "Fuzzy";
- White, Black and Greys must have equal RG and B Components
- Colors without strong Primary Components will usually sort into the Orange Group
iRev Reverses the Sorted Order Completely
eg Black > Dark Grey ... > Dark Red > White for Default iLtDShadeM
The Shade Mask, iLtDShadeM, may be used to Control the Sort Order of Shades within each Group
Setting a Group's Bit in iLtDShadeM to 1 causes that Group to be Sorted in Light to Dark Order (if iRev is False)
eg the Default Value of (&H4 + &H8 + &H10 =) &H1C causes
Groups 1 & 2 to be Sorted D>L (0's in iLtDShadeM)
Groups 3 to 5 to be Sorted L>D
RaC > Sort >
SortAreas
SortAreas (
iRa As Variant,
Optional iByCols As Boolean )
As Range
'190926a
Returns iRa with it's Areas Sorted by Rows, or By
Columns if iByCols is SetOn
Returns Nothing if iRa is Not a Valid Range
Returns Nothing if iRa is Not a Valid Range
RaC > Modify >
we_RCAMode
Row & Column Addition Modes
Enumeration
`161100j RaC.AddRs() and future RaC.AddCs()
we_rcaApp
we_rcaIns
we_rcaUseCb
we_rcaPartCbRoC
we_rcaDisCbDX
we_rcaDisNoCbDX
we_rcaCutCb
we_rcaToEach
we_rcaDisSel
Append Blank RoCs, Coping Format from Above/Left (Default)
Insert " Below/Right
Append/Insert Copies from the Clipboard, rather than Blank RoCs
Use a Partial Clipboard RoC to Fill Appended/Inserted RoCs
Disable we_rcxCbD
Disable we_rcxNoCbD
Cut Clipboard Source Range after Append/Inserts
The Default Appends 1 Paste Range After the Target Range
Set we_rcaToEach to Append Before/Insert After Each Row/Column of the Target Range
Disable Selection of Target plus Added Range after the Edit
we_rcaIns
we_rcaUseCb
we_rcaPartCbRoC
we_rcaDisCbDX
we_rcaDisNoCbDX
we_rcaCutCb
we_rcaToEach
we_rcaDisSel
Append Blank RoCs, Coping Format from Above/Left (Default)
Insert " Below/Right
Append/Insert Copies from the Clipboard, rather than Blank RoCs
Use a Partial Clipboard RoC to Fill Appended/Inserted RoCs
Disable we_rcxCbD
Disable we_rcxNoCbD
Cut Clipboard Source Range after Append/Inserts
The Default Appends 1 Paste Range After the Target Range
Set we_rcaToEach to Append Before/Insert After Each Row/Column of the Target Range
Disable Selection of Target plus Added Range after the Edit
RaC > Modify >
AddRs
AddRs (
ByVal iTarRa As Range,
Optional iMode As we_RCAMode = we_rcaApp, _
Returns the NO Rows Added, which is 0 if an Exception (returned by oaExc)
Occurs; see we_RCAx
By Default 1 Blank Row is Appended after iTarRa, with the same Format as
the Last Row of iTarRa
iMode Values can be combined to modify this Default behaviour; see we_RCAMode
The Multiplier iMx modifies the NO Repititions eg the NO Rows Appended in
Default iMode
If we_rcaUseCb is Set, the Rows Added will be filled using Range Data that
has been Copied** to the Clipboard (the CbRa). CbRa must be either
1) Any Range Data if we_rcaPartCbRoC Reset.
iMx Copies of CbRa.EntireRows are Added
2) N Cells from a Single Row if we_rcaPartCbRoC Set.
iMx Rows are Added, and each is filled with Repeating
Copies of the N Cells, out to the NO UsedRange Columns.
This usually leaves a Partial Copy of CbRa at the End
of each Row (unless N is a factor of the NO Used Range
Columns)
Otherwise, ie if we_rcaPartCbRoC Set and the CbRa has >1 Row,
we_rcxCbM1RoC is Set in oaExc
3) Additionally, if we_rcaCutCb is Set, CbRa and iTar Must
Not Overlap "Row-Wise".
ie No Part of CbRa can be in the Same Row as Any Part
of iTar, or else we_rcxCbOlap is Set in oaExc
**Note that CbRa must have been Copied (not Cut) to the Clipboard
AddRs from Clipboard Truth Table
Cb has Copied
we_rcaUseCb Range Data? we_rcaDisCbDX Cb is Rows Added oaExc
False No x Unchanged Blank .
" Yes False " None we_rcxCbD
" " True Cleared Blank .
we_rcaDisNoCbDX
True Yes x Unchanged** Copies .
" No False Unchanged None we_rcxNoCbD
" " True " Blank .
**Cleared for Cut
If iTarRa is in the ActiveSheet, AddRs Selects the the Union of (the EntireRows
of iTarRa and the Rows Added), unless we_rcaDisSel is Set
Optional iMx As Long = 1,
Optional oaExc As we_RCAx )
As Long
'190116a
Appends or Inserts EntireRows to the Target Range (iTarRa) Returns the NO Rows Added, which is 0 if an Exception (returned by oaExc)
Occurs; see we_RCAx
By Default 1 Blank Row is Appended after iTarRa, with the same Format as
the Last Row of iTarRa
iMode Values can be combined to modify this Default behaviour; see we_RCAMode
The Multiplier iMx modifies the NO Repititions eg the NO Rows Appended in
Default iMode
If we_rcaUseCb is Set, the Rows Added will be filled using Range Data that
has been Copied** to the Clipboard (the CbRa). CbRa must be either
1) Any Range Data if we_rcaPartCbRoC Reset.
iMx Copies of CbRa.EntireRows are Added
2) N Cells from a Single Row if we_rcaPartCbRoC Set.
iMx Rows are Added, and each is filled with Repeating
Copies of the N Cells, out to the NO UsedRange Columns.
This usually leaves a Partial Copy of CbRa at the End
of each Row (unless N is a factor of the NO Used Range
Columns)
Otherwise, ie if we_rcaPartCbRoC Set and the CbRa has >1 Row,
we_rcxCbM1RoC is Set in oaExc
3) Additionally, if we_rcaCutCb is Set, CbRa and iTar Must
Not Overlap "Row-Wise".
ie No Part of CbRa can be in the Same Row as Any Part
of iTar, or else we_rcxCbOlap is Set in oaExc
**Note that CbRa must have been Copied (not Cut) to the Clipboard
AddRs from Clipboard Truth Table
Cb has Copied
we_rcaUseCb Range Data? we_rcaDisCbDX Cb is Rows Added oaExc
False No x Unchanged Blank .
" Yes False " None we_rcxCbD
" " True Cleared Blank .
we_rcaDisNoCbDX
True Yes x Unchanged** Copies .
" No False Unchanged None we_rcxNoCbD
" " True " Blank .
**Cleared for Cut
If iTarRa is in the ActiveSheet, AddRs Selects the the Union of (the EntireRows
of iTarRa and the Rows Added), unless we_rcaDisSel is Set
RaC > Modify >
we_RCAx
Row & Column Addition Exceptions
Enumeration
`161100k RaC.AddRs() and future RaC.AddCs()
we_rcxNone
we_rcxInvTR
we_rcxCbD
we_rcxNoCbD
we_rcxCbM1RoC
we_rcxCbOlap
Invalid Target Range
we_rcaUseCb is Reset, and the Clipboard Contains Copied Range Data
" Set, " Doesn't Contain "
we_rcaPartCbRoC is Set and the Clipboard Contains More than 1 RoC
we_rcaCutCb is Set and the Target and Clipboard Ranges Overlap "RoC-Wise"
we_rcxInvTR
we_rcxCbD
we_rcxNoCbD
we_rcxCbM1RoC
we_rcxCbOlap
Invalid Target Range
we_rcaUseCb is Reset, and the Clipboard Contains Copied Range Data
" Set, " Doesn't Contain "
we_rcaPartCbRoC is Set and the Clipboard Contains More than 1 RoC
we_rcaCutCb is Set and the Target and Clipboard Ranges Overlap "RoC-Wise"
RaC > Modify
FillRand
FillRand (
Optional iRa As Range,
Optional ByVal ivNDPs As Long = 4, _
and Fills iRa with random values in the same range
iRa may be omitted; if it is not then iRa(1,1) is always the same Value as the Return
Random Single Numbers are generated using the VB Rnd()Function.
These are then Scaled using iMx and iOff, and the result is Truncated to ivNDPs Decimal Places
eg for iMx = 10.0 and iOff= -5.0, the values are scaled to Between -5.0 and 5.0 (if ivNDPs is 1)
Optional iMx As Double = 1#,
Optional iOff As Double = 0# )
As String
'190829d
By Default, Returns a Random String Value >=0 and <1.000 to 4 Decimal Places,and Fills iRa with random values in the same range
iRa may be omitted; if it is not then iRa(1,1) is always the same Value as the Return
Random Single Numbers are generated using the VB Rnd()Function.
These are then Scaled using iMx and iOff, and the result is Truncated to ivNDPs Decimal Places
eg for iMx = 10.0 and iOff= -5.0, the values are scaled to Between -5.0 and 5.0 (if ivNDPs is 1)
RaC > Modify
ExtrRa
ExtrRa (
iRa As Range,
Optional iCutOriSel As Boolean )
As Boolean
'181114b
Extracts a Copy of iRa to a New Worksheet, and
Selects this Copy in the New Worksheet
If iCutOriSel is Set, the Selection is Cut (rather than Copied) from the Original Worksheet
Fails if iRa is not a Valid Range
The New Worksheet is a Copy of the Original, with everything except iRa Cleared
This means that the in New Worksheet
- All Row & Column Dimensions are retained
- the Range Outside the New Selection retains the same Number Format(s), but is Empty
- All Non-Range Objects are Copied
If iCutOriSel is Set, the Selection is Cut (rather than Copied) from the Original Worksheet
Fails if iRa is not a Valid Range
The New Worksheet is a Copy of the Original, with everything except iRa Cleared
This means that the in New Worksheet
- All Row & Column Dimensions are retained
- the Range Outside the New Selection retains the same Number Format(s), but is Empty
- All Non-Range Objects are Copied
RaC > Modify
CopyVals
CopyVals (
iFromRa As Range,
oToOCe As Range )
As Boolean
'181116a
Copies all iFromRa's Values to the Range beginning at
Cell oToOCe(1,1)
Fails if either Range is Null, or the Output Range extends past a Sheet Boundary
Doesn't use the Clipboard
Only copies Values
If the Copy To Range and iFromRa Overlap, iFromRa is Overwritten
http://excelexperts.com/copy-values-vba
Fails if either Range is Null, or the Output Range extends past a Sheet Boundary
Doesn't use the Clipboard
Only copies Values
If the Copy To Range and iFromRa Overlap, iFromRa is Overwritten
http://excelexperts.com/copy-values-vba
RaC > Modify
we_CCFn
Cell Comment Functions
Enumeration
`161100m RaC.CmtFns()
we_ccfRead
we_ccfWrite
we_ccfApp
we_ccfWriOrApp
we_ccfDel
we_ccfWrite
we_ccfApp
we_ccfWriOrApp
we_ccfDel
RaC > Modify
CmtFns
CmtFns (
iRa As Range,
iFn As we_CCFn,
Optional ioText As String, _
Returns the NO Comments Acted On (0 if iRa is Invalid)
ioText Sets the Text to Write, or Recieves the Last Comment Read or Deleted, in Ra
iFmt & oCom are only relevant to we_ccfWrite and we_ccfApp
The Default iFmt is Excel's default Format for we_ccfWrite, or No Change for we_ccfApp
If you assign iFmt any other XlHAlign Value,
Comments are formatted in Default WasteNot Comment Format, with that
Horizontal Alignment
oCom is the Last Comment Object Acted On in iRa
Optional iFmt As XlHAlign = xlHAlignDistributed,
Optional oCom As Comment )
As Long
'181117a
Reads from, Writes to, Appends to or Deletes a Ranges's CommentsReturns the NO Comments Acted On (0 if iRa is Invalid)
ioText Sets the Text to Write, or Recieves the Last Comment Read or Deleted, in Ra
iFmt & oCom are only relevant to we_ccfWrite and we_ccfApp
The Default iFmt is Excel's default Format for we_ccfWrite, or No Change for we_ccfApp
If you assign iFmt any other XlHAlign Value,
Comments are formatted in Default WasteNot Comment Format, with that
Horizontal Alignment
oCom is the Last Comment Object Acted On in iRa