Excel 2007 UDF/Formula for highlighted cell

Excel does not provide facilities for sorting or filtering a range of cells by the colour of the cells, or for counting the instances of a particular colour. Here is a User Defined Functions(UDF) that will do the trick.

This UDF will return an array of colorindex values that can be used in standard worksheet functions. For exapmle: ColorIndex(A1)

To create a new UDF in Excel 2007, open Developer -> Visual Basic Editor -> Insert -> Module

'---------------------------------------------------------------------
' ColorIndex Function
'---------------------------------------------------------------------
' Function:    Returns the colorindex of the supplied range
' Synopsis:    Initially, gets a colorindex value for black and white
'              from the activeworkbook colour palette
'              Then works through each cell in  the supplied range and
'              determines the colorindex, and adds to array
'              Finishes by returning acumulated array
' Variations:  Determines cell colour (interior) or text colour (font)
'              Default is cell colour
' Constraints: Does not count colours set by conditional formatting
'---------------------------------------------------------------------
' Author:      Bob Phillips
'              Additions for ranges suggested by Harlan Grove
'---------------------------------------------------------------------


'---------------------------------------------------------------------
Function ColorIndex(rng As Range, _
                    Optional text As Boolean = False) As Variant
'---------------------------------------------------------------------
Dim cell As Range, row As Range
Dim i As Long, j As Long
Dim iWhite As Long, iBlack As Long
Dim aryColours As Variant

    If rng.Areas.Count > 1 Then
        ColorIndex = CVErr(xlErrValue)
        Exit Function
    End If

    iWhite = WhiteColorindex(rng.Worksheet.Parent)
    iBlack = BlackColorindex(rng.Worksheet.Parent)

    If rng.Cells.Count = 1 Then
        If text Then
            aryColours = DecodeColorIndex(rng, True, iBlack)
        Else
            aryColours = DecodeColorIndex(rng, False, iWhite)
        End If

    Else
        aryColours = rng.Value
        i = 0

        For Each row In rng.Rows
            i = i + 1
            j = 0

            For Each cell In row.Cells
                j = j + 1

                If text Then
                    aryColours(i, j) = _
                      DecodeColorIndex(cell,True,iBlack)
                Else
                    aryColours(i, j) = _
                      DecodeColorIndex(cell,False,iWhite)
                End If

            Next cell

        Next row

    End If

    ColorIndex = aryColours

End Function

'---------------------------------------------------------------------
Private Function WhiteColorindex(oWB As Workbook)
'---------------------------------------------------------------------
Dim iPalette As Long
    WhiteColorindex = 0
    For iPalette = 1 To 56
        If oWB.Colors(iPalette) = &HFFFFFF Then
            WhiteColorindex = iPalette
            Exit Function
        End If
    Next iPalette
End Function

'---------------------------------------------------------------------
Private Function BlackColorindex(oWB As Workbook)
'---------------------------------------------------------------------
Dim iPalette As Long
    BlackColorindex = 0
    For iPalette = 1 To 56
        If oWB.Colors(iPalette) = &H0 Then
            BlackColorindex = iPalette
            Exit Function
        End If
    Next iPalette
End Function

'---------------------------------------------------------------------
Private Function DecodeColorIndex(rng As Range, _
                                  text As Boolean, _
                                  idx As Long)
'---------------------------------------------------------------------
Dim iColor As Long
    If text Then
        iColor = rng.font.ColorIndex
    Else
        iColor = rng.Interior.ColorIndex
    End If
    If iColor < 0 Then
        iColor = idx
    End If
    DecodeColorIndex = iColor
End Function

'---------------------------------------------------------------------
' End of ColorIndex Function
'---------------------------------------------------------------------
				

How to migrate mailbox between IMAP Servers with imapsync

imapsync software is a command line tool allowing incremental and recursive imap transfers from one mailbox to another, both anywhere on the internet or in your local network.

imapsync is useful for imap account migration or imap account backup.

imapsync is not adequate for maintaining two active imap accounts in synchronization where the user plays independently on both sides. Use offlineimap (written by John Goerzen) for this purpose.

————————————————

First, create same mailbox on the new mail server.

Then, install imapsync on CentOS: (It doesn’t matter where we install imapsync – we can even install it on a third server.)
yum install imapsync

I’ll use the following data for migration
Old mail server: mail1.mazentop.com
New mail server: mail2.mazentop.com
Old mailbox: support@mazentop.com
New Mailbox: support@mazentop.com
Save old mailbox password in file: /etc/mailpass1
Save new mailbox password in file: /etc/mailpass2

Migrate the old email in support@mazentop.com on server mail1 to the new mailbox support@mazentop.com on server mail2:
imapsync --host1 mail1.mazentop.com --user1 support@mazentop.com --passfile1 /etc/mailpass1 --host2 mail2.mazentop.com --user2 support@mazentop.com --passfile2 /etc/mailpass2

How to pause PowerShell until the external process finished?

By default, if you launch a Win32 process from PowerShell, control returns immediately to the PowerShell and doesn’t wait for the process to terminate.

We can use [diagnostics.process] to start a Window’s batch job (or application) and wait until the job finished/terminated:
$batfile = [diagnostics.process]::Start("D:\Demo\My_Script.bat")
$batfile.WaitForExit()

Then the Powershell script resumes with the next line.