Learn Excel to work faster

Let’s Gain the Excel Knowledge to Create Useful Tools, to Solve Problems by using Excel  functions, pivot tables, conditional formatting, and charts with clear examples.

IMPORTANT SHORT CUTS IN EXCEL

Excel Shortcuts with Alt+

Alt+Enter                                        Start a new line in the same cell.


Alt+Tab                                             Switch between open applications.


Alt+Esc                                          Switch between Applications on the Task Bar


Alt+E                                                Edit option in the current program.


Alt+F                                             File option menu in the current program.


Alt+Print Screen                           Create screen shoot of the current page.


Alt+=                                                Auto Sum


ALT+;                                             Select the visible cells in the current selection.


Alt or F10                                       Activate the menu


Alt+Down arrow                       Display Auto Complete list


Alt+’                                                 Format Style dialog box


Alt+F1                                             Insert Chart


Alt+F2                                             Save As


Alt+F4                                             Exit


Alt+F8                                             Macro dialog box


Alt+F11                                           Visual Basic Editor


ALT+;                                             Select the visible cells in the current selection.

ALT Codes
Alt Code Symbol
Filled Arrows
Alt 16
Alt 17
Alt 254
Alt 30
Alt 31
Line Arrows
Alt 23
Alt 24
Alt 25
Alt 26
Alt 27

 

Excel Shortcuts with Ctrl +

Shortcut key                                   Action


 Ctrl+A                                              Select All


Ctrl+B                                             Bold


Ctrl+C                                             Copy


Ctrl+D                                             Fill Down


Ctrl+E                                              Flash Fill


Ctrl+F                                              Find


Ctrl+G                                             Goto


Ctrl+H                                             Replace


Ctrl+I                                               Italic


Ctrl+K                                             Insert Hyperlink


Ctrl+N                                             New Workbook


Ctrl+O                                             Open


Ctrl+P                                              Print


Ctrl+R                                             Fill Right


Ctrl+S                                              Save


Ctrl+U                                             Underline


Ctrl+V                                             Paste


Ctrl W                                             Close the Document


Ctrl+X                                             Cut


Ctrl+Y                                             Repeat


Ctrl+Z                                              Undo


Ctrl+F3                                            Define name


Ctrl+F4                                            Close


Ctrl+F5                                            XL, Restore window size


Ctrl+F6                                            Next workbook window


Ctrl+F7                                            Move window


Ctrl+F8                                            Resize window


Ctrl+F9                                            Minimize workbook


Ctrl+F10                                          Maximize or restore window


Ctrl+F11                                          Inset 4.0 Macro sheet


Ctrl+F12                                          File Open


Ctrl++                                              Insert


Ctrl+-                                               Delete


Ctrl+1                                              Format cells dialog box


Ctrl+2                                              Bold


Ctrl+3                                              Italic


Ctrl+4                                              Underline


Ctrl+5                                              Strike through


Ctrl+6                                              Show/Hide objects


Ctrl+7                                              Show/Hide Standard toolbar


Ctrl+8                                              Toggle Outline symbols


Ctrl+9                                              Hide rows


Ctrl+0                                              Hide columns


CTRL+/                                           Select the array containing the active cell.


CTRL+\                                           In a selected row, select the cells that don’t match the formula or static value in the active cell.


CTRL+[                                          Select all cells directly referenced by formulas in the selection.


CTRL+]                                          Select cells that contain formulas that directly reference the active cell.


Ctrl+Enter                                      Fill the selected cell range with the current entry.


Ctrl+Spacebar                                Select the entire column.


CTRL+ Down Arrow                    Move to the end of the line or paragraph.


CTRL+Up Arrow                            Move to the beginning of a line or paragraph.


CTRL+Right Arrow                       Move one word to the right.


Ctrl+Left Arrow                              Move one word to the left.


Ctrl+Del                                            Delete one word to the right of the cursor.


Ctrl+Back Space                            Delete one word to the left of the cursor. 


Ctrl+Home                                      Move cursor to the beginning of the document.


Ctrl+End                                           Move cursor to the end of the document.


Ctrl+Space                                       Reset highlighted text to default font.


Ctrl+2                                              Bold


Ctrl+3                                              Italic


Ctrl+4                                              Underline


Ctrl+5                                              Strike through

Excel Shortcuts with Shift+

Shift                                                 Hold down shift for additional functions in Excel’s menu


Shift+F1                                          What’s This?


Shift+F2                                          Edit cell comment


Shift+F3                                          Paste function into formula


Shift+F4                                          Find Next


Shift+F5                                          Find


Shift+F6                                          Previous Pane


Shift+F8                                          Add to selection


Shift+F9                                          Calculate active worksheet


Shift+F10                                        Display shortcut menu


Shift+F11                                        New worksheet


Shift+F12                                        Save


Shift+Space bar                               Select the entire row


Shift+Back Space                 With multiple cells selected, select only the active cell.


 

Excel Shortcut with Alt+Shift+

 


 

Alt+Shift+F1                                   New worksheet


Alt+Shift+F2                                   Save


Alt+Shift+D                                   Insert current Date


Alt+Shift+T                                    Insert current Time


Ctrl+Shift+!                                    Comma format


[email protected]                                  Time format


Ctrl+Shift+#                                    Date format


Ctrl+Shift+$                                    Currency format


Ctrl+Shift+%                                  Percent format


Ctrl+Shift+^                                   Exponential format


Ctrl+Shift+&                                  Place outline border around selected cells


Ctrl+Shift+_                                    Remove outline border


 

Ctrl+Shift+*                                    Select the current region around the active cell. In a PivotTable report, select the entire PivotTable report.


Ctrl+Shift+(                                    Unhide rows


Ctrl+Shift+)                                    Unhide columns


Shift+Ctrl+Tab                               In toolbar: previous toolbar


Shift+Ctrl+F                                   Font Drop Down List


Shift+Ctrl+F                              Font tab of Format Cell Dialog box


Shift+Ctrl+P                                   Point size Drop Down List


CTRL+SHIFT+O                          Select all cells that contain comments.


 

 

CTRL+SHIFT+|                             In a selected column, select the cells that don’t match the formula or static value in the active cell.


CTRL+SHIFT+{                            Select all cells directly or indirectly referenced by formulas in the selection.


CTRL+SHIFT+}                            Select cells that contain formulas that directly or indirectly reference the active cell.


 

Ctrl+Shift+Space Bar       Selects the entire worksheet. If the worksheet contains data, CTRL+SHIFT+SPACEBAR selects the current region. Pressing CTRL+SHIFT+SPACEBAR a second time selects the entire worksheet. When an object is selected, CTRL+SHIFT+SPACEBAR selects all objects on a worksheet


 

Excel Shortcut with Ctrl+Shift+

Ctrl+Shift+F3                                 Create name by using names of row and column labels


Ctrl+Shift+F6                                 Previous Window


Ctrl+Shift+A                                   Insert argument names into formula


Ctrl+Shift+C                                  Create a new Contact


Ctrl+Shift+F                              Font tab of Format Cell Dialog box


Ctrl+Shift+I                                 Open the inbox


Ctrl+Shift+J                                 Create a new Journal Entry


Ctrl+Shift+L                                    Insert or remove filters in a row


Ctrl+Shift+O                                   Select all cells that contain comments.


Ctrl+Shift+P                                   Point size Drop Down List


Ctrl+Shift+U                                    Expand the Formula Bar to view a long formula


Ctrl+Shift+~                                    General format


Ctrl+Shift+!                                    Comma format


[email protected]                                  Time format


Ctrl+Shift+#                                    Date format


Ctrl+Shift+$                                    Currency format


Ctrl+Shift+%                                  Percent format


Ctrl+Shift+^                                   Exponential format


Ctrl+Shift+&                                  Place outline border around selected cells


Ctrl+Shift+_                                    Remove outline border


Ctrl+Shift+*                                    Select the current region around the active cell. In a Pivot-table report, select the entire Pivot-table report.


Ctrl+Shift+(                                    Un-hide rows


Ctrl+Shift+)                                    Unhide columns


Ctrl+Shift+Tab                               In toolbar: previous toolbar


 


 


 


 

 

CTRL+SHIFT+|                             In a selected column, select the cells that don’t match the formula or static value in the active cell.


CTRL+SHIFT+{                            Select all cells directly or indirectly referenced by formulas in the selection.


CTRL+SHIFT+}                            Select cells that contain formulas that directly or indirectly reference the active cell.


 

Ctrl+Shift+Space Bar       Selects the entire worksheet. If the worksheet contains data, CTRL+SHIFT+SPACEBAR selects the current region. Pressing CTRL+SHIFT+SPACEBAR a second time selects the entire worksheet. When an object is selected, CTRL+SHIFT+SPACEBAR selects all objects on a worksheet


 

Excel Shortcut with Ctrl+Alt+Shift

Alt+Shift+F1                                    New work Sheet


Alt+Shift+F2                          Rechecks dependent formulas and then calculates all cells in all open workbooks,including cells not marked as needing to be calculated.


Ctrl+Alt+F9                                    Calculate all worksheets in all open workbooks, regardless of whether they have changed since the last calculation.


 


Ctrl+Alt+Shift+F9                          Rechecks dependent formulas and then calculates all cells in all open workbooks,including cells not marked as needing to be calculated.


 

Excel Shortcuts with Function key

 

F1                                                     Help


F2                                                     Edit


F3                                                     Paste Name


F4                                                     Repeat last action


F4                                                     While typing a formula, switch between absolute/relative refs


F5                                                     Goto


F6                                                     Next Pane


F7                                                     Spell check


F8                                                     Extend mode


F9                                                     Recalculate all workbooks


F10                                                   Activate Menubar


F11                                                   New Chart


F12                                                   Save As

IMPORTANT SETTINGS IN EXCEL

Copy an Excel Sheet with Page Setup to a New Book in Excel

1. Open both the Excel workbook containing your desired print settings and the workbook to which you want to copy the settings. Bring up the workbook, and then the worksheet, where your desired settings are located.
2. Right-click the name of the worksheet on the tab located just below the spreadsheet. Click “Move or Copy” from the list of options that appear.
3. Click the drop-down menu under “To book:,” and then click the workbook to which you want to copy the settings. Click “(move to end)” from the list of worksheets, and place a check mark next to “Create a copy” at the bottom of the window. Click “OK” and the second workbook appears on the screen, with a new copy of your original worksheet inserted into the collection of worksheets.
4. Click on the tab for the new copy of the worksheet, located just beneath the spreadsheet. Then click the “Page Layout” tab at the top of the screen.
5. Hold “Ctrl” and click on the tab for every other sheet in the workbook that you want to have the new print settings.
6. Click the small arrow located in the bottom right corner of the Page Setup area of the ribbon to open the Page Setup window. Click “OK” to transfer the print settings to all the selected sheets.
7. Click on the tab for any worksheet in the workbook, other than the one you copied over. Then right-click on the tab for the worksheet you copied over and click “Delete.”
 

Copy Excel page setup settings from one sheet to another

Transferring the settings from one sheet to the another, as follows:

  1. Select the existing sheet, the source sheet, that contains the settings you want to transfer.
  2. Select the target sheet(s) — the sheets you want to update —  by pressing [Ctrl] and clicking each sheet tab.
  3. Select Page Setup from the File menu and click OK.

Excel Shortcuts with Shift key

Shift                                                 Hold down shift for additional functions in Excel’s menu


Shift+F1                                          What’s This?


Shift+F2                                          Edit cell comment


Shift+F3                                          Paste function into formula


Shift+F4                                          Find Next


Shift+F5                                          Find


Shift+F6                                          Previous Pane


Shift+F8                                          Add to selection


Shift+F9                                          Calculate active worksheet


Shift+F10                                        Display shortcut menu


Shift+F11                                        New worksheet


Shift+F12                                        Save


Shift+Spacebar                               Select the entire row


SHIFT+BACKSPACE                  With multiple cells selected, select only the active cell.


 

Excel Shortcut with Ctrl+Shift+Alt

 


Ctrl+Alt+F9                                    Calculate all worksheets in all open workbooks, regardless of whether they have changed since the last calculation.


Ctrl+Alt+Shift+F9                          Rechecks dependent formulas and then calculates all cells in all open workbooks,including cells not marked as needing to be calculated.


Shift+Ctrl+F6                                 Previous workbook window


Ctrl+Shift+F3                                 Create name by using names of row and column labels


Ctrl+Shift+F6                                 Previous Window


Alt+Shift+F1                                   New worksheet


Alt+Shift+F2                                   Save


Ctrl+Shift+A                                   Insert argument names into formula


Ctrl+Shift+~                                    General format


Ctrl+Shift+!                                    Comma format


[email protected]                                  Time format


Ctrl+Shift+#                                    Date format


Ctrl+Shift+$                                    Currency format


Ctrl+Shift+%                                  Percent format


Ctrl+Shift+^                                   Exponential format


Ctrl+Shift+&                                  Place outline border around selected cells


Ctrl+Shift+_                                    Remove outline border


Ctrl+Shift+*                                    Select the current region around the active cell. In a PivotTable report, select the entire PivotTable report.


Ctrl+Shift+(                                    Unhide rows


Ctrl+Shift+)                                    Unhide columns


Shift+Ctrl+Tab                               In toolbar: previous toolbar


Shift+Ctrl+F                                   Font Drop Down List


Shift+Ctrl+F+F                              Font tab of Format Cell Dialog box


Shift+Ctrl+P                                   Point size Drop Down List


CTRL+SHIFT+O                          Select all cells that contain comments.


 

CTRL+SHIFT+|                             In a selected column, select the cells that don’t match the formula or static value in the active cell.


CTRL+SHIFT+{                            Select all cells directly or indirectly referenced by formulas in the selection.


CTRL+SHIFT+}                            Select cells that contain formulas that directly or indirectly reference the active cell.


SHIFT+BACKSPACE                  With multiple cells selected, select only the active cell.


CTRL+SHIFT+SPACEBAR       Selects the entire worksheet. If the worksheet contains data, CTRL+SHIFT+SPACEBAR selects the current region. Pressing CTRL+SHIFT+SPACEBAR a second time selects the entire worksheet. When an object is selected, CTRL+SHIFT+SPACEBAR selects all objects on a worksheet


 

Excel Shortcuts with Function key

 

F1                                                     Help


F2                                                     Edit


F3                                                     Paste Name


F4                                                     Repeat last action


F4                                                     While typing a formula, switch between absolute/relative refs


F5                                                     Goto


F6                                                     Next Pane


F7                                                     Spell check


F8                                                     Extend mode


F9                                                     Recalculate all workbooks


F10                                                   Activate Menubar


F11                                                   New Chart


F12                                                   Save As

IMPORTANT FUNCTIONS & FORMULAS

Counting of members in a Family using COUNTIF?

Purpose
To count the members in a Family
Syntax

=COUNTIF($B$2:$B$4037,B2)

Here B column indicates family ID and 4037 last row number

How may members of a Family submitted Aadhar COUNTIFS?

Purpose
To count how may members in a Family & among them how many submitted Aadhar
Syntax

=COUNTIFS($B$2:$B$4038,B3,$D$2:$D$4038,”*”)

Here Column is Family ID and Column D Aadhar Number

Excel PROPER Function

 
Purpose
Capitalize the first letter in each word
Return value
Text in proper case.
Syntax
=PROPER (text)

ram is a good boy —> Ram Is A Good Boy

Subtraction cells only if both have a value in Excel else it will be Blank

subtraction two cells in excel but only if both cells have a value. More specifically in my case the formula in cell C2 is currently

=B2-A2 but I only want this to be calculated when B2 has a value or A2 has a value. I tried this formula

=IF(AND(B2<>"",A2<>""),B2-A2," ")

You can use the ISBLANK function:

=IF(OR(ISBLANK(A2),ISBLANK(B2)),"",B2-A2)

Use of Wildcards in Excel

Excel provides three “wildcards” for matching text in formulas:

Character Name Purpose
* Asterisk Match zero or more characters
? Question mark Match any one character
~ Tilde Match literal wildcard

Wildcards can be used alone or combined to get a variety of matching behaviors:

Usage Behavior Will match
? Any one character “A”, “5”, “c”, “z”, etc.
?? Any two characters “AA”, “AZ”,”7q” ,”zz”, etc.
??? Any three characters “Jet”, “AAA”, “ccc”, etc.
* Any characters “apple”, “APPLE”, “A100”, etc.
*th Ends in “th” “bath”, “fourth”, etc.
c* Starts with “c” “Cat”, “CAB”, “cindy”, “candy”, etc.
?* At least one character “a”, “b”, “ab”, “ABCD”, etc.
???-?? 5 characters with hypen “ABC-99″,”100-ZT”, etc.
*~? Ends in question mark “Hello?”, “Anybody home?”, etc.
*xyz* Contains “xyz” “code is XYZ”, “100-XYZ”, “XyZ90”, etc.

Here are a few examples of using wildcards for criteria in the COUNTIFS function.

=COUNTIFS(A1:A100,"*red*") // count cells that contain "red"
=COUNTIFS(A1:A100, "www*") // count cells starting with "www"
=COUNTIFS(A1:A100,"?????") // count cells with 5 characters

First Date and Last Date of a month

The Excel DATEVALUE function converts a date represented as text into a proper Excel date:

Purpose Syntax Return value
1st date of a month =DATEVALUE (“1″&month name cell&Year cell) Excel code of 1st date of the month of the year
Last date of the Month =EOMONTH(1st date of the month cell,0) Excel code of last date of the month
List of all dates of a Month =if(1st date cell < last date cell, 1st date cell+1,””) Next date of 1st date

 

 

Excel flip horizontal to vertical and vice versa

Excel TRANSPOSE Function
Purpose
Flip the orientation of a range of cells
Return value
An array in a new orientation.
Syntax
=TRANSPOSE (array)
Enter the TRANSPOSE function as an array formula that contains same number of cells as array, using Control + Shift + Enter.
Purpose Syntax Return value
     
     
     

 

 

Excel TRIM Function

Purpose 
Remove extra spaces from text
Return value 
Text with extra spaces removed.
Syntax 
=TRIM (text)

Clean up raw Stu-burn data in Excel

How to clean up raw data for processing in Excel. if you have multiple spaces in between numbers you can easily clean it through demonstrated formulas which are stated below.
Formula 1: =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160),””)))
Formula 2: =SUBSTITUTE(A2,” “,””)

To get Current Date and Present Time

Purpose 
To get current Date & Time
Return value 
 
Syntax 
=Today()
To get Present Date & Time
=now()
To get current time

=TEXT(NOW(), “hh:mm:ss AM/PM”)

 

USED EXCEL VBA CODES

Excel VBA Code to copy the entire data of a sheet and paste the same in a new sheet of RC wise FPL

There are no features or formulas can help you to solve this task directly in Excel, but you can create a User Defined Function to finish it. Please do with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Window.

2. Click Insert > Module, and paste the following code in the Module Window.


 
Sub New_Sheet()

‘ New_Sheet Macro

‘ Keyboard Shortcut: Ctrl+Shift+Q

Range(“A12:AD12”).Select

Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-16
End Sub

delete the blank columns from the data, follow below given steps and code

  • Open the VBE page to press the key Alt+F11
  • Insert the module to write the code
  • Write the below mentioned code:

 
Sub Delete_Columns()

Dim C As Integer

C = ActiveSheet.Cells.SpecialCells(xlLastCell).Column

Do Until C = 0

If WorksheetFunction.CountA(Columns(C)) = 0 Then

Columns(C).Delete

End If

C = C - 1

Loop

End Sub

Member Count Aadhar Count and Seeding Percentage

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select aadhar_Count
    Click Run
     


 
 
Sub Aadhar_Count()
'
' Aadhar_Count Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
Range("K2").Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Range("K2:M2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Range("K1").Select
ActiveCell.FormulaR1C1 = "Members"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Aadhar"
Range("M1").Select
ActiveCell.FormulaR1C1 = "Seeding %"
Range("P10:P11").Select
Range("P11").Activate
Columns("K:M").Select
Selection.ColumnWidth = 20.11
Range("K2").Select
ActiveWindow.SmallScroll Down:=-20
ActiveCell.FormulaR1C1 = "=COUNTIF(R1C2:R20000C2,RC[-9])"
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=COUNTIFS(R1C2:R20000C2,RC[-10],R1C10:R20000C10,""*"")"
Range("L3").Select
ActiveWindow.SmallScroll Down:=-16
Range("M2").Select
ActiveCell.FormulaR1C1 = "=ROUND((RC[-1]/RC[-2]%),2)"
Range("M3").Select
ActiveWindow.SmallScroll Down:=-12
Range("M2").Select
ActiveCell.FormulaR1C1 = "=ROUND((RC[-1]/RC[-2]%),2)"
Range("M2").Select
Selection.NumberFormat = "0.0"
Selection.NumberFormat = "0.00"
Range("K2").Select
Selection.Copy
Range("I2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 2).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range("L2").Select
Application.CutCopyMode = False
Selection.Copy
Range("I2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range("M2").Select
Application.CutCopyMode = False
Selection.Copy
Range("I2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 4).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range("N2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Columns("K:M").Select
Selection.ColumnWidth = 7.11
Range("O5").Select
ActiveWindow.SmallScroll Down:=-16
Cells.Replace What:="*/ ", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Range("I1").Select
ActiveCell.FormulaR1C1 = "Address"
Range("N7").Select
ActiveWindow.SmallScroll Down:=-20
Columns("C:E").Select
Selection.ColumnWidth = 12.89
Selection.ColumnWidth = 15.11
Columns("A:A").Select
With Selection
.HorizontalAlignment = xlGeneral
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
Range("D9").Select
ActiveWindow.SmallScroll Down:=-28
Columns("J:J").ColumnWidth = 11.78
ActiveWindow.SmallScroll Down:=-136
Range("K2:M2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("N11").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("H1").Select
ActiveCell.FormulaR1C1 = "AAY ?"
Range("N4").Select
ActiveWindow.SmallScroll Down:=-52
End Sub

Member Count Aadhar Count and Seeding Percentage at member ID

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.

    Test the code:

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select aadhar_Count
    Click Run 


 

Sub Count_Member_Aadhar()

‘ Member_Aadhar_Count Macro
‘When new column Beneficiary ID found


Application.ScreenUpdating = False
Range(“L2:N2”).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Range(“C1”).FormulaR1C1 = “Ben ID”
Range(“I1”).FormulaR1C1 = “AAY ?”
Range(“J1”).FormulaR1C1 = “Address”
Range(“L1”).FormulaR1C1 = “Members”
Range(“M1”).FormulaR1C1 = “Aadhar”
Range(“N1”).FormulaR1C1 = “Seeding %”
Range(“L2”).Select
ActiveCell.FormulaR1C1 = “=COUNTIF(R1C2:R20000C2,RC[-10])”
Range(“M2”).Select
ActiveCell.FormulaR1C1 = _
“=COUNTIFS(R1C2:R20000C2,RC[-11],R1C11:R20000C11,””*””)”
Range(“N2”).Select
ActiveCell.FormulaR1C1 = “=ROUND((RC[-1]/RC[-2]%),2)”
Range(“N2”).NumberFormat = “0.00”
Range(“L2”).Select
Application.CutCopyMode = False
Selection.Copy
Range(“H2”).End(xlDown).Select
ActiveCell.Offset(0, 4).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range(“M2”).Select
Application.CutCopyMode = False
Selection.Copy
Range(“H2”).Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 5).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range(“N2”).Select
Application.CutCopyMode = False
Selection.Copy
Range(“H2”).Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 6).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Columns(“D:F”).Select
Selection.ColumnWidth = 15.11
Columns(“L:N”).Select
Selection.ColumnWidth = 7.11
Columns(“K:K”).ColumnWidth = 11.78
Cells.Replace What:=”*/ “, Replacement:=””, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Columns(“A:A”).Select
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
Range(“L2:N2”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range(“N4”).Select
Application.ScreenUpdating = True

End Sub

Page Setup after member and Aadhar Count

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.

    Test the code:
    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select aadhar_Count
    Click Run


 

Sub Page_Setup()

‘ Page_Setup Macro

‘ Keyboard Shortcut: Ctrl+Shift+O

Application.ScreenUpdating = False
Dim row As Integer, N As Integer
N = Cells(Rows.Count, “K”).End(xlUp).row
For row = N To 2 Step -1
If Not IsEmpty(Range(“K” & row)) Then Range(“A” & row).EntireRow.Delete
Next row
Range(“A2”).Select
ActiveCell.FormulaR1C1 = “1”
Range(“A3”).Select
ActiveCell.FormulaR1C1 = “2”
Range(“A2:A3”).Select
Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
Columns(“N:N”).Select
Selection.EntireColumn.Hidden = True
Range(“A1”).Select
ActiveCell.FormulaR1C1 = “S N”
Range(“B1”).Select
ActiveCell.FormulaR1C1 = “F N”
Range(“E1”).Select
ActiveCell.FormulaR1C1 = “Spouse”
Columns(“G:G”).Select
Selection.Delete Shift:=xlToLeft
Columns(“H:H”).Select
Selection.Delete Shift:=xlToLeft
Columns(“I:I”).Select
Selection.Cut
Columns(“M:M”).Select
Selection.Insert Shift:=xlToRight
Range(“I1”).Select
ActiveCell.FormulaR1C1 = “M”
Range(“J1”).Select
ActiveCell.FormulaR1C1 = “A”
Range(“K1”).Select
ActiveCell.FormulaR1C1 = “%”
Range(“L1”).Select
ActiveCell.FormulaR1C1 = “Remarks”

With Selection
Rows(“2:2”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.RowHeight = 24
End With
Columns(“A:A”).ColumnWidth = 3.67
Columns(“B:B”).ColumnWidth = 3.67
Columns(“C:C”).ColumnWidth = 6.89
Columns(“D:D”).ColumnWidth = 15.89
Columns(“E:E”).ColumnWidth = 9.44
Columns(“F:F”).ColumnWidth = 14.89
Columns(“G:G”).ColumnWidth = 5.89
Columns(“H:H”).ColumnWidth = 10.89
Columns(“I:I”).ColumnWidth = 2.67
Columns(“J:J”).ColumnWidth = 2.67
Columns(“K:K”).ColumnWidth = 0#
Columns(“L:L”).ColumnWidth = 14
Rows(“1:1”).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range(“A1:L1”).Select
With Selection.Font
.Name = “Arial”
.Size = 18
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Merge
Rows(“1:1”).RowHeight = 21.8
Application.CutCopyMode = False
With ActiveSheet.PageSetup
.PrintTitleRows = “$1:$2”
.PrintTitleColumns = “”
End With
ActiveSheet.PageSetup.PrintArea = “”
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = “”
.CenterHeader = “”
.RightHeader = “”
.LeftFooter = “”
.CenterFooter = “Page &P of &N”
.RightFooter = “”
.LeftMargin = Application.InchesToPoints(0.078)
.RightMargin = Application.InchesToPoints(0.078)
.TopMargin = Application.InchesToPoints(0.078)
.BottomMargin = Application.InchesToPoints(0.47)
.HeaderMargin = Application.InchesToPoints(0.27)
.FooterMargin = Application.InchesToPoints(0.078)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
Application.PrintCommunication = True
Range(“L3”).Select
Application.ScreenUpdating = True
End Sub

VBA code to Delete Matched rows Blank rows and Page setup

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select Delete_Matched
    Click Run
     


Sub Delete_Matched()

‘ Delete Macro
With ActiveSheet
.AutoFilterMode = False
With Range(“K1”, Range(“K” & Rows.Count).End(xlUp))
.AutoFilter 1, “Matched”
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
Columns(“K:K”).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

Range(“L2:M2”).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Range(“K2”).Select
Cells.Replace What:=”*/ “, Replacement:=””, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:= _
“Unmatched(100-Due to Personal Identity information did not match)”, _
Replacement:=”100-Name”, LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”Unmatched(998-Invalid Aadhar Number)”, Replacement:= _
“998-Invalid”, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:=”Unmatched(998-Invalid Aadhaar Number)”, Replacement:= _
“998-Invalid”, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:=”Unmatched(997-Aadhaar Suspended)”, Replacement:= _
“997-Suspend”, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False

Range(“K1”).Select
ActiveCell.FormulaR1C1 = “Status”
Range(“I1”).Select
ActiveCell.FormulaR1C1 = “Address”
Columns(“M:M”).Select
Selection.Delete Shift:=xlToLeft
Range(“L1”).Select
ActiveCell.FormulaR1C1 = “Remarks”
Columns(“A:A”).Select
Range(“A2”).Select
ActiveCell.FormulaR1C1 = “1”
Range(“A3”).Select
ActiveCell.FormulaR1C1 = “2”
Range(“A2:A3”).Select

Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
Range(“B3”).Select

ActiveWindow.SmallScroll Down:=-4
Columns(“F:F”).Select
Selection.Delete Shift:=xlToLeft
Columns(“G:G”).Select
Selection.Delete Shift:=xlToLeft
Range(“J5”).Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = “”
.PrintTitleColumns = “”
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = “”
Application.PrintCommunication = False
Application.PrintCommunication = True

Range(“H1”).Select
ActiveCell.FormulaR1C1 = “Aadhaar”
Range(“J3”).Select

ActiveWindow.SmallScroll Down:=-4
Rows(“1:1”).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range(“A1:J1”).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Rows(“1:1”).RowHeight = 21
With Selection.Font
.Name = “Arial”
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range(“A1:J1”).Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = “$1:$2”
.PrintTitleColumns = “”
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = “”
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = “”
.CenterHeader = “”
.RightHeader = “”
.LeftFooter = “”
.CenterFooter = “Page &P of &N”
.RightFooter = “”
.LeftMargin = Application.InchesToPoints(0.078740157480315)
.RightMargin = Application.InchesToPoints(0.078740157480315)
.TopMargin = Application.InchesToPoints(0.078740157480315)
.BottomMargin = Application.InchesToPoints(0.511811023622047)
.HeaderMargin = Application.InchesToPoints(0.275590551181102)
.FooterMargin = Application.InchesToPoints(0.236220472440945)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = “”
.EvenPage.CenterHeader.Text = “”
.EvenPage.RightHeader.Text = “”
.EvenPage.LeftFooter.Text = “”
.EvenPage.CenterFooter.Text = “”
.EvenPage.RightFooter.Text = “”
.FirstPage.LeftHeader.Text = “”
.FirstPage.CenterHeader.Text = “”
.FirstPage.RightHeader.Text = “”
.FirstPage.LeftFooter.Text = “”
.FirstPage.CenterFooter.Text = “”
.FirstPage.RightFooter.Text = “”
End With
Application.PrintCommunication = True
Range(“B2”).Select
ActiveCell.FormulaR1C1 = “F N”
Range(“A2”).Select
ActiveCell.FormulaR1C1 = “S N”
Range(“C4”).Select
Columns(“A:A”).ColumnWidth = 4.33
Columns(“B:B”).ColumnWidth = 4.44
Columns(“C:C”).ColumnWidth = 16.67
Columns(“D:D”).ColumnWidth = 10.11
Columns(“E:E”).ColumnWidth = 11.78
Columns(“F:F”).ColumnWidth = 6.56
Columns(“G:G”).ColumnWidth = 11.44
Columns(“H:H”).ColumnWidth = 10.44
Columns(“J:J”).ColumnWidth = 8.67

Rows(“3:3”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.RowHeight = 15
Rows(“3:8677”).EntireRow.AutoFit
Range(“J4”).Select
End Sub

VBA code to Convert all sheets to one PDF

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select Delete_Matched
    Click Run
     


Sub Convert_to_one_PDF()
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=”C:\Users\Desktop\Allsheets.pdf”, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

VBA code to Remove Special Character

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select Delete_Matched
    Click Run
     


Function RemoveSPChar(allc as string)
dim i as integer
for i=1 to len(allc)
CurChar = Asc(Mid(allc,i,1))
Numeric =Mid(allc,1,1)
If CurChar>=65 And CurChar<=90 or CurChar >=97 And CurChar <=122 Or Numeric >=0 And Numeric <=9 Then
NewName = NewName + Mid(allc,i,1)
End If
Next
RemoveSpChar=NewName
End Function

VBA code to Split Names using formula

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select Delete_Matched
    Click Run
     


‘Function for FIRST NAME

Function firstname(allc As String)
Dim i As Integer
For i = 1 To Len(allc)
c_char = Mid(allc, i, 1)
If Asc(c_char) = 32 Then
GoTo ENDLOOP
Else
NEWTEXT = NEWTEXT & Mid(allc, i, 1)
End If
Next i
ENDLOOP:
firstname = NEWTEXT

End Function

‘Function for MIDDLE NAME

Function midname(allc As String)
Dim i As Integer
For i = 1 To Len(allc)
c_char = Mid(allc, i, 1)
If Asc(c_char) = 32 Then

SP_POS = Application.WorksheetFunction.Find(” “, allc, 1)

GoTo ENDLOOP
Else
End If
Next i
ENDLOOP:
For i = SP_POS + 1 To Len(allc)
c_char = Mid(allc, i, 1)
If Asc(c_char) = 32 Then
GoTo ENDLOOP1
Else
NEWTEXT = NEWTEXT & Mid(allc, i, 1)
End If
Next i

ENDLOOP1:
midname = NEWTEXT
End Function

‘Funciton for LAST NAME

Function lastname(allc As String)
Dim i As Integer
For i = 1 To Len(allc)
c_char = Mid(allc, i, 1)
If Asc(c_char) = 32 Then
SP_POS = Application.WorksheetFunction.Find(” “, allc, 1)
GoTo ENDLOOP
Else
End If
Next i
ENDLOOP:
For i = SP_POS + 1 To Len(allc)
c_char = Mid(allc, i, 1)
If Asc(c_char) = 32 Then
sp_pos2 = Application.WorksheetFunction.Find(” “, allc, SP_POS + 1)
GoTo ENDLOOP1
Else
End If
Next i
ENDLOOP1:
For i = sp_pos2 + 1 To Len(allc)
NEWTEXT = NEWTEXT & Mid(allc, i, 1)
Next i
lastname = NEWTEXT
End Function

FPS wise MIS Report

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select FPS Wise Count

    Click Run

  • Download the VBA Code
  • FPS_Wise_Count

     


Attribute VB_Name = “FPS_Wise_Count”
Sub FPS_Wise_Count()Application.ScreenUpdating = False
Application.EnableEvents = False

Range(“A8:X682”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Range(“J4”).Select
Dim Col As Long, ColCnt As Long, rng As Range
Application.Calculation = xlCalculationManual

On Error GoTo Exits:

If Selection.Columns.Count > 1 Then
Set rng = Selection
Else
Set rng = Range(Columns(1), Columns(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column()))
End If
ColCnt = 0
For Col = rng.Columns.Count To 1 Step -1
If Application.WorksheetFunction.CountA(rng.Columns(Col).EntireColumn) = 0 Then
rng.Columns(Col).EntireColumn.Delete
ColCnt = ColCnt + 1
End If
Next Col

Exits:

Range(“F1:I1”).UnMerge
Range(“F1:G1”).Merge
Range(“H1:I1”).Merge
Range(“H1:I1”).FormulaR1C1 = “Verified Aadhar”
Range(“H2”).FormulaR1C1 = “Family”
Range(“I2”).FormulaR1C1 = “Members”
Range(“J1:K1”).FormulaR1C1 = “Balance to Seed”
Range(“M1:O1”).UnMerge
Range(“L1:M1”).Merge
Range(“L1:M1”).FormulaR1C1 = “Validation Pending”
Range(“L2”).FormulaR1C1 = “Family”
Range(“M2”).FormulaR1C1 = “Members”
Range(“N2”).FormulaR1C1 = “Mismatch Member %”
Range(“O:O”).EntireColumn.Delete
Range(“J3:N4”).Select
Range(Selection, Selection.End(xlDown)).ClearContents
Range(“H1:N3”).Select
Range(Selection, Selection.End(xlDown)).Borders.LineStyle = xlContinuous
Rows(“1:2”).RowHeight = 25
Range(“A1:N2”).Select
With Selection
.Borders.LineStyle = xlContinuous
.VerticalAlignment = xlCenter
.WrapText = True
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Columns(“C:C”).ColumnWidth = 24.11
Columns(“B:B”).ColumnWidth = 12.56
Columns(“A:A”).ColumnWidth = 4
Columns(“A:A”).Select
With Selection
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.ShrinkToFit = True
End With
Range(“J3”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-6]-RC[-4]”
Range(“K3”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-6]-RC[-4]”
Range(“L3”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-6]-RC[-4]”
Range(“M3”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-6]-RC[-4]”
Range(“J3:M3”).Select
Application.CutCopyMode = False
Selection.Copy
Range(“I3”).End(xlDown).Select
ActiveCell.Offset(0, 1).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range(“D3”).End(xlDown).Select
ActiveCell.EntireRow.EntireRow.Delete
Selection.Delete Shift:=xlUp
Range(“B3”).Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range(“A1:C1”).UnMerge
Range(“A1:A2”).Merge
Range(“B1:B2”).Merge
Range(“C1:C2”).Merge
Range(“N1:N2”).Merge
Rows(“1:1”).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range(“N4”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-1]/RC[-7]%”
Range(“N4”).NumberFormat = “0.00”
Range(“N4”).Select
Application.CutCopyMode = False
Selection.Copy
Range(“I4”).End(xlDown).Select
ActiveCell.Offset(0, 5).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range(“A4”, Range(“A4”).End(xlToRight).End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:=”=$C4=”””””
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection
.WrapText = False
End With
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(0, 255, 255)
.TintAndShade = 0
End With
Range(“A4”, Range(“A4”).End(xlToRight).End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:=”=$N4>10″
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 0)
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Range(“A4”, Range(“A4”).End(xlToRight).End(xlDown)).Select
With Selection
.Borders.LineStyle = xlContinuous
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
End With
Range(“D4”, Range(“D4”).End(xlToRight).End(xlDown)).Select
With Selection.Font
.Name = “Arial”
.Size = 11
End With
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = “$1:$3”
.PrintTitleColumns = “”
End With
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.148)
.RightMargin = Application.InchesToPoints(0.088)
.TopMargin = Application.InchesToPoints(0.128)
.BottomMargin = Application.InchesToPoints(0.148)
.HeaderMargin = Application.InchesToPoints(0.07)
.FooterMargin = Application.InchesToPoints(0.07)
.PrintQuality = 300
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.Zoom = 100
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
Application.PrintCommunication = True
Rows(“4:720”).EntireRow.RowHeight = 20
Range(“D4”).Select
Selection.End(xlDown).Select
ActiveCell.EntireRow.EntireRow.RowHeight = 30
Range(“F9”).Select
Columns(“J:K”).Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns(“J:K”).Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range(“J3”).Select
ActiveCell.FormulaR1C1 = “Family”
Range(“K3”).Select
ActiveCell.FormulaR1C1 = “Members”
Range(“L3”).Select
ActiveCell.FormulaR1C1 = “Family”
Range(“M3”).Select
ActiveCell.FormulaR1C1 = “Members”
Range(“J2:K2”).Merge
Range(“L2:M2”).Merge
Range(“J2:K2”).Select
ActiveCell.FormulaR1C1 = “Y Day Pending”
Range(“L2:M2”).Select
ActiveCell.FormulaR1C1 = “Daily Validation”
Range(“L4”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-2]-RC[4]”
Range(“M4”).Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = “=RC[-2]-RC[4]”
Range(“L4:M4”).Select
Selection.Copy
Range(“I3”).End(xlDown).Select
ActiveCell.Offset(0, 3).Range(“A1”).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Rows(“1:1”).RowHeight = 24.6
Range(“A1:O1”).Merge
Range(“A1:O1”).Select
Range(“A1:O1”).FormulaR1C1 = “FPS WISE AADHAR SEEDING & VALIDATION REPORT OF GANJAM DISTRICT AS ON”
Range(“P1:R1”).Merge
Range(“P1:R1”).Select
ActiveCell.FormulaR1C1 = “=today()”
Range(“A1:O1”, “P1:R1”).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Font.Name = “Arial”
.Font.Size = 16
.Font.Bold = True
End With
Range(“B4”).End(xlDown).Font.Size = 14
Columns(“L:P”).ColumnWidth = 6.11
Columns(“Q”).ColumnWidth = 9
Range(“L4”).Select
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

The Countdown Begins!

Day(s)

:

Hour(s)

:

Minute(s)

:

Second(s)

Automated Cash Book

Download Automated Cash BookExcel Study

FPS wise Daily FPS VBA Code

This VBA code can be used to get the Daily MIS report from FPS wise count report. It will provide the out put of MIS Report with Block wise Subtotal Reports upto page setup in landscape.

View the VBA Code

IMPORTANT EXCEL VBA CODES

Excel VBA Code to convert Numbers to Words International format without Currency

There are no features or formulas can help you to solve this task directly in Excel, but you can create a User Defined Function to finish it. Please do with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Window.

2. Click Insert > Module, and paste the following code in the Module Window.

3. Save and close this code and go back the worksheet, in a blank cell, enter this formula =NumberstoWords(A2)A2 is the cell you want to convert the number to English word), see screenshot:

4. Then press Enter key, and select cell C2 then drag the fill handle to the range that you want to contain this formula. All the numeric values have been converted their corresponding English words.


 
Function NumberstoWords(ByVal pNumber)
'Updateby20140220
Dim Dollars
arr = Array(""""" Thousand "" Million "" Billion "" Trillion ")
pNumber = Trim(Str(pNumber))
xDecimal = InStr(pNumber, ".")
If xDecimal > 0 Then
pNumber = Trim(Left(pNumber, xDecimal - 1))
End If
xIndex = 1
Do While pNumber <> ""
xHundred = ""
xValue = Right(pNumber, 3)
If Val(xValue) <> 0 Then
xValue = Right("000" & xValue, 3)
If Mid(xValue, 1, 1) <> "0" Then
xHundred = GetDigit(Mid(xValue, 1, 1)) & " Hundred "
End If
If Mid(xValue, 2, 1) <> "0" Then
xHundred = xHundred & GetTens(Mid(xValue, 2))
Else
xHundred = xHundred & GetDigit(Mid(xValue, 3))
End If
End If
If xHundred <> "" Then
Dollars = xHundred & arr(xIndex) & Dollars
End If
If Len(pNumber) > 3 Then
pNumber = Left(pNumber, Len(pNumber) - 3)
Else
pNumber = ""
End If
xIndex = xIndex + 1
Loop
NumberstoWords = Dollars
End Function
Function GetTens(pTens)
Dim Result As String
Result = ""
If Val(Left(pTens, 1)) = 1 Then
Select Case Val(pTens)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else
Select Case Val(Left(pTens, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit(Right(pTens, 1))
End If
GetTens = Result
End Function
Function GetDigit(pDigit)
Select Case Val(pDigit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

Excel VBA Code to convert Date To Words

There are no features or formulas can help you to solve this task directly in Excel, but you can create a User Defined Function to finish it. Please do with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Window.

2. Click Insert > Module, and paste the following code in the Module Window.

3. Save and close this code and go back the worksheet, in a blank cell, enter this formula =DateToWords(A2)A2 is the cell you want to convert the number to English word), see screenshot:

4. Then press Enter key, and select cell C2 then drag the fill handle to the range that you want to contain this formula. All the numeric values have been converted their corresponding English words.


Download the code from Text File  Date to Words

‘Date to Words by Learn More Copy Below Code

Function DateToWords(ByVal xRgVal As Date) As String

Dim xYear As String
Dim Hundreds As String
Dim Decades As String
Dim xTensArr As Variant
Dim xOrdArr As Variant
Dim xCardArr As Variant
xOrdArr = Array(“First”, “Second”, “Third”, _
“Fourth”, “Fifth”, “Sixth”, _
“Seventh”, “Eighth”, “Nineth”, _
“Tenth”, “Eleventh”, “Twelfth”, _
“Thirteenth”, “Fourteenth”, _
“Fifteenth”, “Sixteenth”, _
“Seventeenth”, “Eighteenth”, _
“Nineteenth”, “Twentieth”, _
“Twenty-first”, “Twenty-second”, _
“Twenty-third”, “Twenty-fourth”, _
“Twenty-fifth”, “Twenty-sixth”, _
“Twenty-seventh”, “Twenty-eighth”, _
“Twenty-nineth”, “Thirtieth”, _
“Thirty-first”)
xCardArr = Array(“”, “One”, “Two”, “Three”, “Four”, _
“Five”, “Six”, “Seven”, “Eight”, “Nine”, “Ten”, “Eleven”, “Twelve”, “Thirteen”, “Fourteen”, “Fifteen”, “Sixteen”, “Seventeen”, “Eighteen”, “Nineteen”)
xTensArr = Array(“Twenty”, “Thirty”, “Forty”, “Fifty”, “Sixty”, “Seventy”, “Eighty”, “Ninety”)
xYear = CStr(Year(xRgVal))
Decades = Mid$(xYear, 3)
If CInt(Decades) < 20 Then
Decades = xCardArr(CInt(Decades))
Else
Decades = xTensArr(CInt(Left$(Decades, 1)) – 2) & ” ” & _
xCardArr(CInt(Right$(Decades, 1)))
End If
Hundreds = Mid$(xYear, 2, 1)
If CInt(Hundreds) Then
Hundreds = xCardArr(CInt(Hundreds)) & ” Hundred “
Else
Hundreds = “”
End If
DateToWords = xOrdArr(Day(xRgVal) – 1) & _
Format$(xRgVal, ” mmmm “) & _
xCardArr(CInt(Left$(xYear, 1))) & _
” Thousand ” & Hundreds & Decades
End Function

 

delete the blank columns from the data, follow below given steps and code

  • Open the VBE page to press the key Alt+F11
  • Insert the module to write the code
  • Write the below mentioned code:

 
Sub Delete_Columns()

Dim C As Integer

C = ActiveSheet.Cells.SpecialCells(xlLastCell).Column

Do Until C = 0

If WorksheetFunction.CountA(Columns(C)) = 0 Then

Columns(C).Delete

End If

C = C - 1

Loop

End Sub

delete the blank rows from the data, follow below given steps and code

  • How to use:
    Copy above code.
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.
      
    Test the code:
     

    Enter some data in random locations on your spreadsheet
    Press Alt + F8 to open the macro dialog box.
    Select DeleteBlankRows
    Click Run
     


 
 
Sub DeleteBlankRows() 
    Dim Rw As Long, RwCnt As Long, Rng As Range 
     
    Application.ScreenUpdating = False 
    Application.Calculation = xlCalculationManual 
     
On Error GoTo Exits: 
     
    If Selection.Rows.Count > 1 Then 
        Set Rng = Selection 
    Else 
        Set Rng = Range(Rows(1), Rows(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row())) 
    End If 
    RwCnt = 0 
    For Rw = Rng.Rows.Count To 1 Step -1 
        If Application.WorksheetFunction.CountA(Rng.Rows(Rw).EntireRow) = 0 Then 
            Rng.Rows(Rw).EntireRow.Delete 
            RwCnt = RwCnt + 1 
        End If 
    Next Rw 
     
Exits: 
    Application.ScreenUpdating = True 
    Application.Calculation = xlCalculationAutomatic 
     
End Sub 
 
Sub DeleteBlankColumns() 
    Dim Col As Long, ColCnt As Long, Rng As Range 
     
    Application.ScreenUpdating = False 
    Application.Calculation = xlCalculationManual 
     
On Error GoTo Exits: 
     
    If Selection.Columns.Count > 1 Then 
        Set Rng = Selection 
    Else 
        Set Rng = Range(Columns(1), Columns(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column())) 
    End If 
    ColCnt = 0 
    For Col = Rng.Columns.Count To 1 Step -1 
        If Application.WorksheetFunction.CountA(Rng.Columns(Col).EntireColumn) = 0 Then 
            Rng.Columns(Col).EntireColumn.Delete 
            ColCnt = ColCnt + 1 
        End If 
    Next Col 
     
Exits: 
    Application.ScreenUpdating = True 
    Application.Calculation = xlCalculationAutomatic 
     
End Sub 

List of top 100 macro Examples (CODES) for VBA beginners

I’ve added all the codes into specific categories so you can find your favorite codes quickly. Just read the title and click on it to get the code.

Basic Codes

These VBA codes will help you to perform some basic tasks in a flash which you frequently do in your spreadsheets.

1. Add Serial Numbers

Sub AddSerialNumbers()
Dim i As Integer
On Error GoTo Last
i = InputBox("Enter Value", "Enter Serial Numbers")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last:Exit Sub
End Sub

2. Insert Multiple Columns

This code helps you to enter multiple columns in a single click. When you run this code it asks you the number columns you want to add and when you click OK, it adds entered number of columns after the selected cell.

Sub InsertMultipleColumns()
Dim i As Integer
Dim j As Integer
ActiveCell.EntireColumn.Select
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert Columns")
For j = 1 To i
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromRightorAbove
Next j
Last: Exit Sub
End Sub

If you want to add columns before the selected cell, replace the xlToRight to xlToLeft in the code.

3. Insert Multiple Rows

Sub InsertMultipleRows()
Dim i As Integer
Dim j As Integer
ActiveCell.EntireRow.Select
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert Columns")
For j = 1 To i
Selection.Insert Shift:=xlToDown, CopyOrigin:=xlFormatFromRightorAbove
Next j
Last: Exit Sub
End Sub

4. Auto Fit Columns

Sub AutoFitColumns()
Cells.Select
Cells.EntireColumn.AutoFit
End Sub

5. Auto Fit Rows

You can use this code to auto-fit all the rows in a worksheet. When you run this code it will select all the cells in your worksheet and instantly auto-fit all the row.

Sub AutoFitRows()
Cells.Select
Cells.EntireRow.AutoFit
End Sub

6. Remove Text Wrap

This code will help you to remove text wrap from the entire worksheet with a single click. It will first select all the columns and then remove text wrap and auto fit all the rows and columns.

Sub AutoFitRows()
Cells.Select
Cells.EntireRow.AutoFit
End Sub

7. Unmerge Cells

This code simply uses the unmerge options which you have on the HOME‌ tab. The benefit of using this code is you can add it to the QAT and unmerge all the cell in the selection.

Sub UnmergeCells()
Selection.UnMerge
End Sub

And if you want to un-merge a specific range you can define that range in the code by replacing the word selection.

8. Open Calculator

In Windows, there is a specific calculator and by using this macro code you can open that calculator directly from Excel.

Sub OpenCalculator()
Application.ActivateMicrosoftApp Index:=0
End Sub

As I mentioned that it’s for windows and if you run this code in the MAC version of VBA you’ll get an error.

9. Add Header/Footer Date

This macro adds a date to the header when you run it. It simply uses the tag “&D” for adding the date. You can also change it to the footer or change the side by replacing the “” with the date tag.

Sub DateInHeader()
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&D"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
End Sub

And if you want to add a specific date instead of the current date you can replace the “&D” tag with that date from the code.

10. Custom Header/Footer

When you run this code, it shows an input box that asks you to enter the text which you want to add as a header, and once you enter it click OK.

Sub CustomHeader()
Dim myText As String
myText = InputBox("Enter your text here", "Enter Text")
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = myText
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
End Sub
 

 

 

Formatting Codes

These VBA codes will help you to format cells and ranges using some specific criteria and conditions.

 

11. Highlight Duplicates from Selection

This macro will check each cell of your selection and highlight the duplicate values.

You can also change the color from the code.

Sub HighlightDuplicateValues()
Dim myRange As Range
Dim myCell As Range
Set myRange = Selection
For Each myCell In myRange
If WorksheetFunction.CountIf(myRange, myCell.Value) > 1 Then
myCell.Interior.ColorIndex = 36
End If
Next myCell
End Sub
 

12. Highlight the Active Row and Column

I really love to use this macro code whenever I have to analyze a data table.

Here are the quick steps to apply this code.

  1. Open VBE (ALT + F11).
  2. Go to Project Explorer (Ctrl + R, If hidden).
  3. Select your workbook & double click on the name of a particular worksheet in which you want to activate the macro.
  4. Paste the code into it and select the “BeforeDoubleClick” from event drop down menu.
  5. Close VBE and you are done.

Remember that, by applying this macro you wi ll not able to edit the cell by double click.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range,
Cancel As Boolean)
Dim strRange As String
strRange = Target.Cells.Address & "," Target.Cells.EntireColumn.Address & "," & _
Target.Cells.EntireRow.Address
Range(strRange).Select
End Sub
 

13. Highlight Top 10 Values

Just select a range and run this macro and it will highlight top 10 values with the green color.

Sub TopTen()
Selection.FormatConditions.AddTop10
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
With Selection.FormatConditions(1)
.TopBottom = xlTop10Top
.Rank = 10
.Percent = False
End With
With Selection.FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
 

14. Highlight Named Ranges

If you are not sure about how many named ranges you have in your worksheet then you can use this code to highlight all of them.

Sub HighlightRanges()
Dim RangeName As Name
Dim HighlightRange As Range
On Error Resume Next
For Each RangeName In ActiveWorkbook.Names
Set HighlightRange = RangeName.RefersToRange
HighlightRange.Interior.ColorIndex = 36
Next RangeName
End Sub
 

15. Highlight Greater than Values

Once you run this code it will ask you for the value from which you want to highlight all greater values.

Sub HighlightGreaterThanValues()
Dim i As Integer
i = InputBox("Enter Greater Than Value", "Enter Value")
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlGreater, Formula1:=i
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
With Selection.FormatConditions(1)
.Font.Color = RGB(0, 0, 0)
.Interior.Color = RGB(31, 218, 154)
End With
End Sub
 

16. Highlight Lower Than Values

Once you run this code it will ask you for the value from which you want to highlight all lower values.

Sub HighlightLowerThanValues()
Dim i As Integer
i = InputBox("Enter Lower Than Value", "Enter Value")
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLower, Formula1:=i
Selection.FormatConditions(Selection.FormatConditions.Count).S
tFirstPriority
With Selection.FormatConditions(1)
.Font.Color = RGB(0, 0, 0)
.Interior.Color = RGB(217, 83, 79)
End With
End Sub
 

17. Highlight Negative Numbers

Select a range of cells and run this code. It will check each cell from the range and highlight all cells the where you have a negative number.

Sub highlightNegativeNumbers()
Dim Rng As Range
For Each Rng In Selection
If WorksheetFunction.IsNumber(Rng) Then
If Rng.Value < 0 Then
Rng.Font.Color= -16776961
End If
End If
Next
End Sub
 

18. Highlight Specific Text

Suppose you have a large data set and you want to check for a particular value. For this, you can use this code. When you run it, you will get an input box to enter the value to search for.

Sub highlightValue()
Dim myStr As String
Dim myRg As Range
Dim myTxt As String
Dim myCell As Range
Dim myChar As String
Dim I As Long
Dim J As Long
On Error Resume Next
If ActiveWindow.RangeSelection.Count> 1 Then
myTxt= ActiveWindow.RangeSelection.AddressLocal
Else
myTxt= ActiveSheet.UsedRange.AddressLocal
End If
LInput: Set myRg= Application.InputBox("please select the data
range:", "Selection Required", myTxt, , , , , 8)
If myRg Is Nothing Then
Exit Sub
If myRg.Areas.Count > 1 Then
MsgBox"not support multiple columns" GoToLInput
End If
If myRg.Columns.Count <> 2 Then
MsgBox"the selected range can only contain two columns "
GoTo LInput
End If
For I = 0 To myRg.Rows.Count-1
myStr= myRg.Range("B1").Offset(I, 0).Value
With myRg.Range("A1").Offset(I, 0)
.Font.ColorIndex= 1
For J = 1 To Len(.Text)
Mid(.Text, J, Len(myStr)) = myStrThen
.Characters(J, Len(myStr)).Font.ColorIndex= 3
Next
End With
Next I
End Sub
 

19. Highlight Cells with Comments

To highlight all the cells with comments use this macro.

Sub highlightCommentCells()
Selection.SpecialCells(xlCellTypeComments).Select
Selection.Style= "Note"
End Sub
 

20. Highlight Alternate Rows in the Selection

By highlighting alternate rows you can make your data easily readable. And for this, you can use below VBA code. It will simply highlight every alternate row in selected range.

Sub highlightAlternateRows()
Dim rng As Range
For Each rng In Selection.Rows
If rng.RowMod 2 = 1 Then
rng.Style= "20% -Accent1"
rng.Value= rng^ (1 / 3)
Else
End If
Next rng
End Sub
 

21. Highlight Cells with Misspelled Words

If you find hard to check all the cells for spelling error then this code is for you. It will check each cell from the selection and highlight the cell where is a misspelled word.

Sub HighlightMisspelledCells()
Dim rng As Range
For Each rng In ActiveSheet.UsedRange
If Not Application.CheckSpelling(word:=rng.Text) Then
rng.Style= "Bad" End If
Next rng
End Sub
 

22. Highlight Cells With Error in the Entire Worksheet

To highlight and count all the cells in which you have an error, this code will help you. Just run this code and it will return a message with the number error cells and highlight all the cells.

Sub highlightErrors()
Dim rng As Range
Dim i As Integer
For Each rng In ActiveSheet.UsedRange
If WorksheetFunction.IsError(rng) Then
i = i + 1 rng.Style = "bad"
End If
Next rng
MsgBox "There are total " & i & " error(s) in this worksheet."
End Sub
 

23. Highlight Cells with a Specific Text in Worksheet

This code will help you to count the cells which have a specific value which you will mention and after that highlight all those cells.

Sub highlightSpecificValues()
Dim rng As Range
Dim i As Integer
Dim c As Variant
c = InputBox("Enter Value To Highlight")
For Each rng In ActiveSheet.UsedRange
If rng = c Then
rng.Style = "Note"
i = i + 1
End If
Next rng
MsgBox "There are total " & i &" "& c & " in this worksheet."
End Sub
 

24. Highlight all the Blank Cells Invisible Space

Sometimes there are some cells which are blank but they have a single space and due to this, it’s really hard to identify them. This code will check all the cell in the worksheet and highlight all the cells which have a single space.

Sub blankWithSpace()
Dim rng As Range
For Each rng In ActiveSheet.UsedRange
If rng.Value = " " Then
rng.Style = "Note"
End If
Next rng
End Sub
 

25. Highlight Max Value In The Range

It will check all the selected cells and highlight the cell with the maximum value.

Sub highlightMaxValue()
Dim rng As Range
For Each rng In Selection
If rng = WorksheetFunction.Max(Selection) Then
rng.Style = "Good"
End If
Next rng
End Sub
 

26. Highlight Min Value In The Range

It will check all the selected cells and highlight the cell with the Minimum value.

Sub highlightMinValue()
Dim rng As Range
For Each rng In Selection
If rng = WorksheetFunction.Min(Selection) Then
rng.Style = "Good"
End If
Next rng
End Sub
 

27. Highlight Unique Values

This codes will highlight all the cells from the selection which has a unique value.

Sub highlightUniqueValues()
Dim rng As Range
Set rng = Selection
rng.FormatConditions.Delete
Dim uv As UniqueValues
Set uv = rng.FormatConditions.AddUniqueValues
uv.DupeUnique = xlUnique
uv.Interior.Color = vbGreen
End Sub
 

28. Highlight Difference in Columns

Using this code you can highlight the difference between two columns (corresponding cells).

Sub columnDifference()
Range("H7:H8,I7:I8").Select
Selection.ColumnDifferences(ActiveCell).Select
Selection.Style= "Bad"
End Sub
 

29. Highlight Difference in Rows

And by using this code you can highlight difference between two row (corresponding cells).

Sub rowDifference()
Range("H7:H8,I7:I8").Select
Selection.RowDifferences(ActiveCell).Select
Selection.Style= "Bad"
End Sub
 

Printing Codes

These macro codes will help you to automate some printing tasks which can further save you a ton of time.

 

30. Print Comments

Use this macro to activate settings to print cell comments in the end of the page. Let’s say you have 10 pages to print, after using this code you will get all the comments on 11th last page.

Sub printComments()
With ActiveSheet.PageSetup
.printComments= xlPrintSheetEnd
End With
End Sub
 

31. Print Narrow Margin

Use this VBA code to take a print with a narrow margin. When you run this macro it will automatically change margins to narrow.

Sub printNarrowMargin()
With ActiveSheet.PageSetup
.LeftMargin= Application
.InchesToPoints(0.25)
.RightMargin= Application.InchesToPoints(0.25)
.TopMargin= Application.InchesToPoints(0.75)
.BottomMargin= Application.InchesToPoints(0.75)
.HeaderMargin= Application.InchesToPoints(0.3)
.FooterMargin= Application.InchesToPoints(0.3)
End With
ActiveWindow.SelectedSheets.PrintOutCopies:=1, Collate:=True,
IgnorePrintAreas:=False
End Sub
 

32. Print Selection

This code will help you print selected range. You don’t need to go to printing options and set printing range. Just select a range and run this code.

Sub printSelection()
Selection.PrintOutCopies:=1, Collate:=True
End Sub
 

33. Print Custom Pages

Instead of using the setting from print options you can use this code to print custom page range.

Let’s say you want to print pages from 5 to 10. You just need to run this VBA code and enter start page and end page.

Sub printCustomSelection()
Dim startpageAs Integer
Dim endpageAs Integer
startpage= InputBox("Please Enter Start Page number.", "Enter Value")
If Not WorksheetFunction.IsNumber(startpage) Then
MsgBox"Invalid Start Page number. Please try again.", "Error"
Exit Sub
End If
endpage= InputBox("Please Enter End Page number.", "Enter Value")
If Not WorksheetFunction.IsNumber(endpage) Then
MsgBox"Invalid End Page number. Please try again.", "Error"
Exit Sub
End If
Selection.PrintOutFrom:=startpage, To:=endpage, Copies:=1
Collate:=True
End Sub
 

Worksheet Codes

These macro codes will help you to control and manage worksheets in an easy way and save your a lot of time.

 

34. Hide all but the Active Worksheet

Now, let’s say if you want to hide all the worksheets in your workbook other than the active worksheet. This macro code will do this for you.

Sub HideWorksheet()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ThisWorkbook.ActiveSheet.Name Then
ws.Visible = xlSheetHidden
End If
Next ws
End Sub
 

35. Unhide all Hidden Worksheets

And if you want to un-hide all the worksheets which you have hide with previous code, here is the code for that.

Sub UnhideAllWorksheet()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
End Sub
 

36. Delete all but the Active Worksheet

If you want to delete all the worksheets other than the active sheet, this macro is useful for you.

When you run this macro it will compare the name of the active worksheet with other worksheets and then delete them.

Sub DeleteWorksheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.name <> ThisWorkbook.ActiveSheet.name Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next ws
End Sub
 

37. Protect all Worksheets Instantly

If you want to protect your all worksheets in one go here is a code for you.

When you run this macro, you will get an input box to enter a password. Once you enter your password, click OK. And make sure to take care about CAPS.

Sub ProtectAllWorskeets()
Dim ws As Worksheet
Dim ps As String
ps = InputBox("Enter a Password.", vbOKCancel)
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:=ps
Next ws
End Sub
 

38. Resize All Charts in a Worksheet

Make all chart same in size. This macro code will help you to make all the charts of the same size. You can change the height and width of charts by changing it in macro code.

Sub Resize_Charts()
Dim i As Integer
For i = 1 To ActiveSheet.ChartObjects.Count
With ActiveSheet.ChartObjects(i)
.Width = 300
.Height = 200
End With
Next i
End Sub
 

39. Insert Multiple Worksheets

You can use this code if you want to add multiple worksheets in your workbook in a single shot.

When you run this macro code you will get an input box to enter the total number of sheets you want to enter.

Sub InsertMultipleSheets()
Dim i As Integer
i = InputBox("Enter number of sheets to insert.", "Enter
Multiple Sheets")
Sheets.Add After:=ActiveSheet, Count:=i
End Sub
 

40. Protect Worksheet

If you want to protect your worksheet you can use this macro code.

All you have to do just mention your password in the code.

Sub ProtectWS()
ActiveSheet.Protect "mypassword", True, True
End Sub
 

41. Un-Protect Worksheet

If you want to unprotect your worksheet you can use this macro code.

All you have to do just mention your password which you have used while protecting your worksheet.

Sub UnprotectWS()
ActiveSheet.Unprotect "mypassword"
End Sub
 

42. Sort Worksheets

This code will help you to sort worksheets in your workbook according to their name.

Sub SortWorksheets()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
& "Clicking No will sort in Descending Order", _
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
ElseIf iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
End Sub
 

43. Protect all the Cells With Formulas

To protect cell with formula with a single click you can use this code.

Sub lockCellsWithFormulas()
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect AllowDeletingRows:=True
End With
End Sub
 

44. Delete all Blank Worksheets

Run this code and it will check all the worksheets in the active workbook and delete if a worksheet is blank.

Sub deleteBlankWorksheets()
Dim Ws As Worksheet
On Error Resume Next
Application.ScreenUpdating= False
Application.DisplayAlerts= False
For Each Ws In Application.Worksheets
If Application.WorksheetFunction.CountA(Ws.UsedRange) = 0 Then
Ws.Delete
End If
Next
Application.ScreenUpdating= True
Application.DisplayAlerts= True
End Sub
 

45. Unhide all Rows and Columns

Instead of unhiding rows and columns on by one manually you can use this code to do this in a single go.

Sub UnhideRowsColumns()
Columns.EntireColumn.Hidden = False
Rows.EntireRow.Hidden = False
End Sub
 

46. Save Each Worksheet as a Single PDF

This code will simply save all the worksheets in a separate PDF file. You just need to change the folder name from the code.

Sub SaveWorkshetAsPDF()
Dimws As Worksheet
For Each ws In Worksheetsws.ExportAsFixedFormat xlTypePDF,
“ENTER-FOLDER-NAME-HERE" & ws.Name & ".pdf" Nextws
End Sub
 

47. Disable Page Breaks

To disable page breaks use this code. It will simply disable page breaks from all the open workbooks.

Sub DisablePageBreaks()
Dim wbAs Workbook
Dim wksAs Worksheet
Application.ScreenUpdating= False
For Each wbIn Application.Workbooks
For Each ShtIn wb.WorksheetsSht.DisplayPageBreaks= False
Next Sht
Next wb
Application.ScreenUpdating= True
End Sub
 

Workbook Codes

These codes will help you to perform workbook level tasks in an easy way and with minimum efforts.

 

48. Create a Backup of a Current Workbook

This is one of the most useful macros which can help you to save a backup file of your current workbook.

It will save a backup file in the same directory where your current file is saved and it will also add the current date with the name of the file.

Sub FileBackUp()
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & _
"" & Format(Date, "mm-dd-yy") & " " & _
ThisWorkbook.name
End Sub
 

49. Close all Workbooks at Once

Use this macro code to close all open workbooks.

This macro code will first check all the workbooks one by one and close them. If any of the worksheets is not saved, you’ll get a message to save it.

Sub CloseAllWorkbooks()
Dim wbs As Workbook
For Each wbs In Workbooks
wbs.Close SaveChanges:=True
Next wb
End Sub
 

50. Copy Active Worksheet into a New Workbook

Let’s say if you want to copy your active worksheet in a new workbook, just run this macro code and it will do the same for you.

It’s a super time saver.

Sub CopyWorksheetToNewWorkbook()
ThisWorkbook.ActiveSheet.Copy _
Before:=Workbooks.Add.Worksheets(1)
End Sub
 

51. Active Workbook in an Email

Use this macro code to quickly send your active workbook in an e-mail.

You can change the subject, email, and body text in code and if you want to send this mail directly, use “.Send” instead of “.Display”.

Sub Send_Mail()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = "[email protected]"
.Subject = "Growth Report"
.Body = "Hello Team, Please find attached Growth Report."
.Attachments.Add ActiveWorkbook.FullName
.display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

52. Add Workbook to a Mail Attachment

Once you run this macro it will open your default mail client and attached active workbook with it as an attachment.

Sub OpenWorkbookAsAttachment()
Application.Dialogs(xlDialogSendMail).Show
End Sub
 

53. Welcome Message

You can use auto_open to perform a task on opening a file and all you have to do just name your macro “auto_open”.

Sub auto_open()
MsgBox "Welcome To ExcelChamps & Thanks for downloading this
file."
End Sub
 

54. Closing Message

You can use close_open to perform a task on opening a file and all you have to do just name your macro “close_open”.

Sub auto_close()
MsgBox "Bye Bye! Don't forget to check other cool stuff on
excelchamps.com"
End Sub
 

55. Count Open Unsaved Workbooks

Let’s you have 5-10 open workbooks, you can use this code to get the number of workbooks which are not saved yet.

Sub VisibleWorkbooks()
Dim book As Workbook
Dim i As Integer
For Each book In Workbooks
If book.Saved = False Then
i = i + 1
End If
Next book
MsgBox i
End Sub
 

Pivot Table Codes

These codes will help you to manage and make some changes in pivot tables in a flash.

 

56. Hide Pivot Table Subtotals

If you want to hide all the subtotals, just run this code.

First of all, make sure to select a cell from your pivot table and then run this macro.

Sub HideSubtotals()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(ActiveCell.PivotTable.name)
If pt Is Nothing Then
MsgBox "You must place your cursor inside of a PivotTable."
Exit Sub
End If
For Each pf In pt.PivotFields
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
End Sub
 

57. Refresh All Pivot Tables

A super quick method to refresh all pivot tables.

Just run this code and all of your pivot tables in your workbook will be refresh in a single shot.

Sub CloseAllWorkbooks()
Dim wbs As Workbook
For Each wbs In Workbooks
wbs.Close SaveChanges:=True
Next wb
End Sub
 

58. Create a Pivot Table

Follow this step by step guide to create a pivot table using VBA.

 

59. Auto Update Pivot Table Range

If you are not using Excel tables then you can use this code to update pivot table range.

Sub UpdatePivotTableRange()
Dim Data_Sheet As Worksheet
Dim Pivot_Sheet As Worksheet
Dim StartPoint As Range
Dim DataRange As Range
Dim PivotName As String
Dim NewRange As String
Dim LastCol As Long
Dim lastRow As Long
'Set Pivot Table & Source Worksheet
Set Data_Sheet = ThisWorkbook.Worksheets("PivotTableData3")
Set Pivot_Sheet = ThisWorkbook.Worksheets("Pivot3")
'Enter in Pivot Table Name
PivotName = "PivotTable2"
'Defining Staring Point & Dynamic Range
Data_Sheet.Activate
Set StartPoint = Data_Sheet.Range("A1")
LastCol = StartPoint.End(xlToRight).Column
DownCell = StartPoint.End(xlDown).Row
Set DataRange = Data_Sheet.Range(StartPoint, Cells(DownCell, LastCol))
NewRange = Data_Sheet.Name & "!" & DataRange.Address(ReferenceStyle:=xlR1C1)
'Change Pivot Table Data Source Range Address
Pivot_Sheet.PivotTables(PivotName). _
ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
'Ensure Pivot Table is Refreshed
Pivot_Sheet.PivotTables(PivotName).RefreshTable
'Complete Message
Pivot_Sheet.Activate
MsgBox "Your Pivot Table is now updated."
End Sub
 

60. Disable/Enable Get Pivot Data

To disable/enable GetPivotData function you need to use Excel option.

But with this code you can do it in a single click.

Sub activateGetPivotData()
Application.GenerateGetPivotData = True
End Sub
Sub deactivateGetPivotData()
Application.GenerateGetPivotData = False
End Sub
 

Charts Codes

Use these VBA codes to manage charts in Excel and save your lot of time.

 

61. Change Chart Type

This code will help you to convert chart type without using chart options from the tab.

All you have to do just specify to which type you want to convert.

Below code will convert selected chart to a clustered column chart.

There are different codes for different types, you can find all those types from here.

Sub ChangeChartType()
ActiveChart.ChartType = xlColumnClustered
End Sub
 

62. Paste Chart as an Image

This code will help you to convert your chart into an image.

You just need to select your chart and run this code.

Sub ConvertChartToPicture()
ActiveChart.ChartArea.Copy
ActiveSheet.Range("A1").Select
ActiveSheet.Pictures.Paste.Select
End Sub
 

63. Add Chart Title

First of all, you need to select your chart and the run this code.

You will get an input box to enter chart title.

Sub AddChartTitle()
Dim i As Variant
i = InputBox("Please enter your chart title", "Chart Title")
On Error GoTo Last
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = i
Last:
Exit Sub
End Sub
 

Advanced Codes

Some of the codes which you can use to preform advanced task in your spreadsheets.

 

64. Hide all the Subtotals

If you want to hide all the subtotals, just run this code.

First of all, make sure to select a cell from your pivot table and then run this macro.

Sub HideSubtotals()
Dim pt As PivotTable
Dim pf As PivotField
On Error Resume Next
Set pt = ActiveSheet.PivotTables(ActiveCell.PivotTable.name)
If pt Is Nothing Then
MsgBox "You must place your cursor inside of a PivotTable."
Exit Sub
End If
For Each pf In pt.PivotFields
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
End Sub
 

65. Create a Table of Content

Let’s say you have more than 100 worksheets in your workbook and it’s hard to navigate now.

Don’t worry this macro code will rescue everything.

When you run this code it will create a new worksheet and create a index of worksheets with a hyperlink to them.

Sub TableofContent()
Dim i As Long
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Table of Content").Delete
Application.DisplayAlerts = True
On Error GoTo 0
ThisWorkbook.Sheets.Add Before:=ThisWorkbook.Worksheets(1)
ActiveSheet.Name = "Table of Content"
For i = 1 To Sheets.Count
With ActiveSheet
.Hyperlinks.Add _
Anchor:=ActiveSheet.Cells(i, 1), _
Address:="", _
SubAddress:="'" & Sheets(i).Name & "'!A1", _
ScreenTip:=Sheets(i).Name, _
TextToDisplay:=Sheets(i).Name
End With
Next i
End Sub
 

66. Convert Range into an Image

Paste selected range as an image.

You just have to select the range and once you run this code it will automatically insert a picture for that range.

Sub PasteAsPicture()
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Pictures.Paste.Select
End Sub
 

67. Insert a Linked Picture

This VBA code will convert your selected range into a linked picture and you can use that image anywhere you want.

Sub LinkedPicture()
Selection.Copy
ActiveSheet.Pictures.Paste(Link:=True).Select
End Sub
 

68. Use Text to Speech

Just select a range and run this code.

Excel will speak all the text what you have in that range, cell by cell.

Sub Speak()
Selection.Speak
End Sub
 

69. Activate Data Entry Form

There is a default data entry form which you can use for data entry.

Sub DataForm()
ActiveSheet.ShowDataForm
End Sub
 

70. Use Goal Seek

Goal Seek can be super helpful for you to solve complex problems.

Learn more about goal seek from here before you use this code.

Sub GoalSeekVBA()
Dim Target As Long
On Error GoTo Errorhandler
Target = InputBox("Enter the required value", "Enter Value")
Worksheets("Goal_Seek").Activate
With ActiveSheet .Range("C7")
.GoalSeek_ Goal:=Target, _
ChangingCell:=Range("C2")
End With
Exit Sub
Errorhandler: MsgBox("Sorry, value is not valid.")
End Sub
 

71. VBA Code to Search on Google

Follow this post to learn how to use this VBA code to search on Google.

Sub SearchWindow32()
Dim chromePath As String
Dim search_string As String
Dim query As String
query = InputBox("Enter here your search here", "Google Search")
search_string = query
search_string = Replace(search_string, " ", "+")
'Uncomment the following line for Windows 64 versions and comment out Windows 32 versions'
chromePath = "C:Program
FilesGoogleChromeApplicationchrome.exe"
'Uncomment the following line for Windows 32 versions and comment out Windows 64 versions
chromePath = "C:Program Files
(x86)GoogleChromeApplicationchrome.exe"
Shell (chromePath & " -url http://google.com/#q=" & search_string)
End Sub
 

Formula Codes

These codes will help you to calculate or get results which often you do with worksheet functions and formulas.

 

72. Convert all Formulas into Values

Simply convert formulas into values.

When you run this macro it will quickly change the formulas into absolute values.

Sub ConvertToValues()
Dim MyRange As Range
Dim MyCell As Range
Select Case MsgBox("You Can't Undo This Action. " & "Save
Workbook First?", vbYesNoCancel, "Alert")
Case Is = vbYes
ThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Set MyRange = Selection
For Each MyCell In MyRange
If MyCell.HasFormula Then
MyCell.Formula = MyCell.Value
End If
Next MyCell
End Sub
 

73. Remove Spaces from Selected Cells

One of the most useful macros from this list.

It will check your selection and then remove all the extra spaces from that.

Sub RemoveSpaces()
Dim myRange As Range
Dim myCell As Range
Select Case MsgBox("You Can't Undo This Action. " & "Save
Workbook First?", _
vbYesNoCancel, "Alert")
Case Is = vbYesThisWorkbook.Save
Case Is = vbCancel
Exit Sub
End Select
Set myRange = Selection
For Each myCell In myRange
If Not IsEmpty(myCell) Then
myCell = Trim(myCell)
End If
Next myCell
End Sub
 

74. Remove Characters from a String

Simply remove characters from the starting of a text string.

All you need is to refer to a cell or insert a text into the function and number of characters to remove from the text string.

It has two arguments “rng” for the text string and “cnt” for the count of characters to remove.

For example: If you want to remove first characters from a cell, you need to enter 1 in cnt.

Public Function removeFirstC(rng As String, cnt As Long)
removeFirstC = Right(rng, Len(rng) - cnt)
End Function
 

75. Add Insert Degree Symbol in Excel

Let’s say you have a list of numbers in a column and you want to add degree symbol with all of them.

Sub degreeSymbol( )
Dim rng As Range
For Each rng In Selection
rng.Select
If ActiveCell <> "" Then
If IsNumeric(ActiveCell.Value) Then
ActiveCell.Value = ActiveCell.Value & "°"
End If
End If
Next
End Sub
 

76. Reverse Text

All you have to do just enter “rvrse” function in a cell and refer to the cell in which you have text which you want to reverse.

Public Function rvrse(ByVal cell As Range) As String
rvrse = VBA.strReverse(cell.Value)
End Function
 

77. Activate R1C1 Reference Style

This macro code will help you to activate R1C1 reference style without using Excel options.

Sub DataForm()
ActiveSheet.ShowDataForm
End Sub
 

78. Activate A1 Reference Style

This macro code will help you to activate A1 reference style without using Excel options.

Sub ActivateA1()
If Application.ReferenceStyle = xlR1C1 Then
Application.ReferenceStyle = xlA1
Else
Application.ReferenceStyle = xlA1
End If
End Sub
 

79. Insert Time Range

With this code, you can insert a time range in sequence from 00:00 to 23:00.

Sub TimeStamp()
Dim i As Integer
For i = 1 To 24
ActiveCell.FormulaR1C1 = i & ":00"
ActiveCell.NumberFormat = "[$-409]h:mm AM/PM;@"
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=0).Select
Next i
End Sub
 

80. Convert Date into Day

If you have dates in your worksheet and you want to convert all those dates into days then this code is for you.

Simply select the range of cells and run this macro.

Sub date2day()
Dim tempCell As Range
Selection.Value = Selection.Value
For Each tempCell In Selection
If IsDate(tempCell) = True Then
With tempCell
.Value = Day(tempCell)
.NumberFormat = "0"
End With
End If
Next tempCell
End Sub
 

81. Convert Date into Year

This code will convert dates into years.

Sub date2year()
Dim tempCell As Range
Selection.Value = Selection.Value
For Each tempCell In Selection
If IsDate(tempCell) = True Then
With tempCell
.Value = Year(tempCell)
.NumberFormat = "0"
End With
End If
Next tempCell
End Sub
 

82. Remove Time from Date

If you have time with the date and you want to remove it then you can use this code.

Sub removeTime()
Dim Rng As Range
For Each Rng In Selection
If IsDate(Rng) = True Then
Rng.Value = VBA.Int(Rng.Value)
End If
Next
Selection.NumberFormat = "dd-mmm-yy"
End Sub
 

83. Remove Date from Date and Time

It will return only time from a date and time value.

Sub removeDate()
Dim Rng As Range
For Each Rng In Selection
If IsDate(Rng) = True Then
Rng.Value = Rng.Value - VBA.Fix(Rng.Value)
End If
NextSelection.NumberFormat = "hh:mm:ss am/pm"
End Sub
 

84. Convert to Upper Case

Select the cells and run this code.

It will check each and every cell of selected range and then convert it into upper case text.

Sub convertUpperCase()
Dim Rng As Range
For Each Rng In Selection
If Application.WorksheetFunction.IsText(Rng) Then
Rng.Value = UCase(Rng)
End If
Next
End Sub
 

85. Convert to Lower Case

This code will help you to convert selected text into lower case text.

Just select a range of cells where you have text and run this code.

If a cell has a number or any value other than text that value will remain same.

Sub convertLowerCase()
Dim Rng As Range
For Each Rng In Selection
If Application.WorksheetFunction.IsText(Rng) Then
Rng.Value= LCase(Rng)
End If
Next
End Sub
 

86. Convert to Proper Case

And this code will convert selected text into the proper case where you have the first letter in capital and rest in small.

Sub convertProperCase()
Dim Rng As Range
For Each Rng In Selection
If WorksheetFunction.IsText(Rng) Then
Rng.Value= WorksheetFunction.Proper(Rng.Value)
End If
Next
End Sub
 

87. Convert to Sentence Case

In text case, you have the first letter of the first word in capital and rest all in words in small for a single sentence and this code will help you convert normal text into sentence case.

Sub convertTextCase()
Dim Rng As Range
For Each Rng In Selection
If WorksheetFunction.IsText(Rng) Then
Rng.Value= UCase(Left(Rng, 1)) & LCase(Right(Rng, Len(Rng) -1))
End If
Next rng
End Sub
 

88. Remove a Character from Selection

To remove a particular character from a selected cell you can use this code.

It will show you an input box to enter the character you want to remove.

Sub removeChar()
Dim Rng As Range
Dim rc As String
rc = InputBox("Character(s) to Replace", "Enter Value")
For Each Rng In Selection
Selection.Replace What:=rc, Replacement:=""
Next
End Sub
 

89. Word Count from Entire Worksheet

It can help you to count all the words from a worksheet.

Sub Word_Count_Worksheet()
Dim WordCnt As Long
Dim rng As Range
Dim S As String
Dim N As Long
For Each rng In ActiveSheet.UsedRange.Cells
S = Application.WorksheetFunction.Trim(rng.Text)
N = 0
If S <> vbNullString Then
N = Len(S) - Len(Replace(S, " ", "")) + 1
End If
WordCnt = WordCnt + N
Next rng
MsgBox "There are total " & Format(WordCnt, "#,##0") & " words
in the active worksheet"
End Sub
 

90. Remove the Apostrophe from a Number

If you have numeric data where you have an apostrophe before each number, you run this code to remove it.

Sub removeApostrophes()
Selection.Value = Selection.Value
End Sub
 

91. Remove Decimals from Numbers

This code will simply help you to remove all the decimals from the numbers from the selected range.

Sub removeDecimals()
Dim lnumber As Double
Dim lResult As Long
Dim rng As Range
For Each rng In Selection
rng.Value= Int(rng)
rng.NumberFormat= "0"
Next rng
End Sub
 

92. Multiply all the Values by a Number

Let’s you have a list of numbers and you want to multiply all the number with a particular.

Just use this code.

Select that range of cells and run this code. It will first ask you for the number with whom you want to multiple and then instantly multiply all the numbers with it.

Sub multiplyWithNumber()
Dim rng As Range
Dim c As Integer c = InputBox("Enter number to multiple",
"Input Required")
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = rng * c
Else
End If
Next rng
End Sub
 

93. Add a Number in all the Numbers

Just like multiplying you can also add a number into a set of numbers.

Sub addNumber()
Dim rngAs Range
DimiAs Integer
i= InputBox("Enter number to multiple", "Input Required")
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value= rng+ i
Else
End If
Next rng
End Sub
 

94. Calculate the Square Root

To calculate square root without applying a formula you can use this code.

It will simply check all the selected cells and convert numbers to their square root.

Sub getSquareRoot()
Dim rngAs Range
Dim i As Integer
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value= Sqr(rng)
Else
End If
Next rng
End Sub
 

95. Calculate the Cube Root

To calculate cube root without applying a formula you can use this code.

It will simply check all the selected cells and convert numbers to their cube root.

Sub getCubeRoot()
Dim rng As Range
Dimi As Integer
For Each rng In Selection
If WorksheetFunction.IsNumber(rng) Then
rng.Value = rng ^ (1 / 3)
Else
End If
Nextrng
End Sub
 

96. Add A-Z Alphabets in a Range

Just like serial numbers you can also insert alphabets in your worksheet. Beloware the code which you can use.

Sub addcAlphabets()
Dim i As Integer
For i= 65 To 90
ActiveCell.Value= Chr(i)
ActiveCell.Offset(1, 0).Select
Next i
End Sub
Sub addsAlphabets()
Dim i As Integer
For i= 97 To 122
ActiveCell.Value= Chr(i)
ActiveCell.Offset(1, 0).Select
Next i
End Sub
 

97. Convert Roman Numbers into Arabic Numbers

Sometimes it’s really hard to understand Roman numbers as serial numbers. This code will help you to convert roman numbers into Arabic numbers.

Sub convertToNumbers()
Dim rng As Range
Selection.Value= Selection.Value
For Each rng In Selection
If Not WorksheetFunction.IsNonText(rng) Then
rng.Value= WorksheetFunction.Arabic(rng)
End If
Next rng
End Sub
 

98. Remove Negative Signs

This code will simply check all the cell in the selection and convert all the negative numbers into positive. Just select a range and run this code.

Sub removeNegativeSign()
Dim rngAs Range
Selection.Value= Selection.Value
For Each rngIn Selection
If WorksheetFunction.IsNumber(rng)
Then rng.Value= Abs(rng)
End If
Next rng
End Sub
 

99. Replace Blank Cells with Zeros

For data where you have blank cells, you can use the below code to add zeros in all those cells. It makes easier to use those cells in further calculations.

Sub replaceBlankWithZero()
Dim rngAs Range
Selection.Value= Selection.Value
For Each rngIn Selection
If rng= "" Or rng= " " Then
rng.Value= "0"
Else
End If
Next rng
End Sub