Skip to main content

Posts

Showing posts with the label Procedures

VBA Procedure to apply borders to a excel range of cells

The following VBA procedure can be used to apply borders to a range of cells Public Sub ApplyBorder(ToRange As Range, intColorIndex As Integer)      On Error Resume Next      With ToRange         With .Borders(xlDiagonalDown)             .LineStyle = xlNone         End With         With .Borders(xlDiagonalUp)             .LineStyle = xlNone         End With                 With .Borders(xlEdgeLeft)             .LineStyle = xlContinuous             .Weight = xlThin        ...

VBA Function to return unique values

'The following function returns a unique list if passed an array of values Public Function UniqueValues(SourceValues As Variant) As Variant 'Returns a variant containing the unique values contained within SourceValues 'If called from a worksheet array formula, returns either a row or column array, as needed. Dim Items As New Collection Dim i As Long, j As Long, m As Long, nCols As Long, nRows As Long, Row As Long Dim rg As Range Dim cel As Variant, Result() As Variant On Error Resume Next Set rg = Application.Caller For Each cel In SourceValues    If cel <> "" Then Items.Add CStr(cel), CStr(cel) Next If rg Is Nothing Then Else     nCols = rg.Columns.Count     nRows = rg.Rows.Count     m = Application.Max(nCols, nRows) End If On Error GoTo 0 i = Items.Count ReDim Result(1 To i) For Row = 1 To i      j = 0     If rg Is Nothing Then         For Each cel In...