How to Count Cells by Font Color in Excel

This post will guide you how to count cells by font color in Excel. How do I Count the number of cells with specific cell Font color by using a User Defined function in Excel.

Count Cells by Font Color


Assuming that you have a list of data in range B1:B9, in which contain some text or numeric values. and you want to count those cells based on Font color. How to accomplish it. You can use an User Defined function to count cells by font color in Excel. Just do the following steps:

Step1# open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

 Get the position of the nth using excel vba1

Step2#  then the “Visual Basic Editor” window will appear.

Step3# click “Insert” ->”Module” to create a new module.

convert column number to letter3

Step4# paste the below VBA code into the code window. Then clicking “Save” button.

count cells by font color2

Function CountCellsByFontColor(rng As Range, Cell As Range)
Dim CellC As Range, ucoll As New Collection, i As Single
i = 0
For Each CellC In rng
    If CellC.Font.ColorIndex = Cell.Font.ColorIndex Then
        i = i + 1
    End If
Next CellC
    CountCellsByFontColor = i
End Function

#5 back to the current worksheet, then type the following formula in a blank cell, and then press Enter key. And drag the AutoFill Handle over to other cells.

=CountCellsByFontColor(B1:B9,D1)

count cells by font color1

This User Defined function will count how many times the font color in Cell C1 mathes each cell in range of cells B1:B9.

 

How to Rename Multiple Files with VBA Macro in Excel

This post will guide you how to rename multiple files in a given directory with VBA Macro in Excel. How do I quickly rename multiple files at once in Excel.

Rename Multiple Files with VBA


Assuming that you have multiple files and the format for all filenames like this: test1.xlsx, test2.xlsx…etc.

rename multiple files with vba2

You want to rename all those files to another certain format in a selected directory at once, how to quickly achieve it in Excel. The best way is that to use an Excel VBA Macro to rename all file names. Just do the following steps:

 

Step1: you need to type all file names into your current worksheet, then create a new column that contain new file name list.

rename multiple files with vba6

Step2: open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1
Step3: then the “Visual Basic Editor” window will appear.

Step4: click “Insert” ->”Module” to create a new module.

export each sheet to csv2

Step5: paste the below VBA code  into the code window. Then clicking “Save” button.

rename multiple files with vba1

Sub RenameMultipleFiles()
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        If .Show = -1 Then
            selectDirectory = .SelectedItems(1)
            dFileList = Dir(selectDirectory & Application.PathSeparator & "*")
        
            Do Until dFileList = ""
                curRow = 0
                On Error Resume Next
                curRow = Application.Match(dFileList, Range("B:B"), 0)
                If curRow > 0 Then
                    Name selectDirectory & Application.PathSeparator & dFileList As _
                    selectDirectory & Application.PathSeparator & Cells(curRow, "D").Value
                End If
        
                dFileList = Dir
            Loop
        End If
    End With
End Sub

Note: the range B:B used to place the origninal file name list, and the Column D is used to store new file name list. So you need to replace those two values as you need in the above VBA code.

Step6: back to the current worksheet, then run the above excel macro. Click Run button.

rename multiple files with vba3

Step7: select one directory that contain files you want to rename  in the Browser dialog box. and click Ok button.

rename multiple files with vba4

Step8: you can go the directory that contain files to check if file names are changed.

rename multiple files with vba5

 

Sort Worksheets in Alphabetical Order

This post will guide you how to sort worksheet tabs in alphabetical order in Excel. How do I sort worksheet by alphabetical order with VBA Macro code in Excel. How to quickly rearrange your worksheet tabs in alphabetical order with VBA code in Excel.

Sort Worksheets in Alphabetical Order


Assuming that you have 5 worksheets in your workbook, and you can sort worksheet tabs by manually. But what if there were 100 tabs? How to quickly sort worksheets? The best way is using VBA code to sort worksheets quickly. Let’s see the below detailed steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

sort worksheets in alphabetical order1

Sub sortWorksheetTabs()
    Dim x As Long
    Dim y As Long
    For x = 1 To Worksheets.Count
        For y = x To Worksheets.Count
            If UCase(Sheets(y).Name) < UCase(Sheets(x).Name) Then
                  Sheets(y).Move before:=Sheets(x)
            End If
        Next
    Next
End Sub

#5 back to the current worksheet, then run the above excel macro. Click Run button.

sort worksheets in alphabetical order2