Skip to main content

Top 100 Useful Excel Macro [VBA] Codes Examples

Yogendra98.blogpost.com
You can automate small as well as heavy tasks with VBA codes.
And do you know with the help of macros, you can break all the limitations of Excel which you think Excel has?
So today, I have listed some of the useful codes examples to help you become more productive in your day to day work.
You can use these codes even if you haven't used VBA before that.
All you have to do just paste these codes in your VBA editor.
Don't Forget: Make sure to download this free PDF checklist where IтАЩve added all these codes (+ two more E-books) for you which you can use to refer them any time in future.
  • `Go to your developer tab and click on "Visual Basic".
click on visual basic editor before you use these useful macros for excel
  • On the left side in "Project Window", right click on the name of your workbook and insert a new module.
add module to paste these useful macros for excel
  • Just paste your codes into the module and close it.
use useful macro codes examples by pasting them into vb editor
  • Now, go to your developer tab and click on the macro button.
useful-macro-codes-examples-to-use-from-macro-options
  • It will show you a window with a list of the macros you have in your file. And, you can run a macro from that list.
useful macro codes examples list from macro options
And now, let's explore these codes.

...a list of top 100 macro 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.
Important: This is my Ultimate Code Vault which I update on monthly basis with new codes. It would be great if you bookmark this page and keep on visiting to new codes every time.

(A) 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

2. Insert Multiple Columns

3. Insert Multiple Rows

4. Auto Fit Columns

5. Auto Fit Rows

6. Remove Text Wrap

7. Unmerge Cells

8. Open Calculator

9. Add Header/Footer Date

10. Custom Header/Footer

(B) Formatting Codes

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

11. Highlight Duplicates from Selection

12. Highlight the Active Row and Column

13. Highlight Top 10 Values

14. Highlight Named Ranges

15. Highlight Greater than Values

16. Highlight Lower Than Values

17. Highlight Negative Numbers

18. Highlight Specific Text

19. Highlight Cells with Comments

20. Highlight Alternate Rows in the Selection

21. Highlight Cells with Misspelled Words

22. Count/Highlight Cells With Error in the Entire Worksheet

23. Count/Highlight Cells With A Specific In Entire Worksheet

24. Highlight all the Cells in a Worksheet which are Blank but have an Invisible Space

25. Highlight Max Value In The Range

26. Highlight Min Value In The Range

27. Highlight Unique Values

28. Highlight Difference in Columns

29. Highlight Difference in Rows

(C) 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

31. Print Narrow Margin

32. Print Selection

33. Print Custom Pages

(D) 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

35. Unhide all Hidden Worksheets

36. Delete all but the Active Worksheet

37. Protect all Worksheets Instantly

38. Resize All Charts in a Worksheet

39. Insert Multiple Worksheets

40. Protect Worksheet

41. Un-Protect Worksheet

42. Sort Worksheets

43. Protect all the Cells With Formulas

44. Delete all Blank Worksheets

45. Unhide all Rows and Columns

46. Save Each Worksheet as a Single PDF

47. Disable Page Breaks

(E) 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

49. Close all Workbooks at Once

50. Copy Active Worksheet into a New Workbook

51. Active Workbook in an Email

52. Add Workbook to a Mail Attachment

53. Welcome Message

54. Closing Message

55. Count Open Unsaved Workbooks

(F). 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

57. Refresh All Pivot Tables

58. Create a Pivot Table

59. Auto Update Pivot Table Range

60. Disable/Enable Get Pivot Data

(G). Charts Codes

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

61. Change Chart Type

62. Paste Chart as an Image

63. Add Chart Title

(H) Advanced Codes

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

64. Save Selected Range as a PDF

65. Create a Table of Content

66. Convert Range into an Image

67. Insert a Linked Picture

68. Use Text to Speech

69. Activate Data Entry Form

70. Use Goal Seek

71. VBA Code to Search on Google

(I) 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

73. Remove Spaces from Selected Cells

74. Remove Characters from a String

75. Add Insert Degree Symbol in Excel

76. Reverse Text

77. Activate R1C1 Reference Style

78. Activate A1 Reference Style

79. Insert Time Range

80. Convert Date into Day

81. Convert Date into Year

82. Remove Time from Date

83. Remove Date from Date and Time

84. Convert to Upper Case

85. Convert to Lower Case

86. Convert to Proper Case

87. Convert to Sentence Case

88. Remove a Character from Selection

89. Word Count from Entire Worksheet

90. Remove the Apostrophe from a Number

91. Remove Decimals from Numbers

92. Multiply all the Values by a Number

93. Add a Number in all the Numbers

94. Calculate the Square Root

95. Calculate the Cube Root

96. Add A-Z Alphabets in a Range

97. Convert Roman Numbers into Arabic Numbers

98. Remove Negative Signs

99. Replace Blank Cells with Zeros

100?
Well, I want you to share your favorite macro code which you use everyday to save your time.
Please share with me in the comment section, IтАЩd love to hear from you.
And in the end, I just want to say that some these codes every day to increase my productivity and IтАЩm sure it will also help you in your work.
I hope you have found this list useful. If yes, then please donтАЩt forget to share this list with your friends.
Download Free PDF Copy
Enter your name and email below to get a Free PDF copy directly into your inbox.

Comments

Interactive Blogposts

OFFSET combined with SUM or AVERAGE_#Yogendra

           OFFSET combined with SUM or AVERAGE Formula: =SUM(B4:OFFSET(B4,0,E2-1)) The OFFSET function on its own is not particularly advanced, but when we combine it with other functions like SUM or AVERAGE we can create a pretty sophisticated formula.  Suppose you want to create a dynamic function that can sum a variable number of cells.  With the regular SUM formula, you are limited to a static calculation, but by adding OFFSET you can have the cell reference move around. How it works:  To make this formula work, we substitute ending reference cell of the SUM function with the OFFSET function.  This makes the formula dynamic and the cell referenced as E2 is where you can tell Excel how many consecutive cells you want to add up. Now weтАЩve got some advanced Excel formulas! Below is a screenshot of this slightly more sophisticated formula in action. Add caption As you see, the SUM formula starts...

рдиреЗрд▓реНрд╕рди рдордВрдбреЗрд▓рд╛

рдордИ 2008 рдореЗрдВ рдордВрдбреЗрд▓рд╛ рджрдХреНрд╖рд┐рдг рдЕрдлреНрд░реАрдХрд╛ рдХреЗ рд░рд╛рд╖реНрдЯреНрд░рдкрддрд┐ рдкрдж рдмрд╣рд╛рд▓ 10 рдордИ 1994 тАУ 14 рдЬреВрди 1999 рд╕рд╣рд╛рдпрдХ рдерд╛рдмреЛ рдореНрд╡реВрдпреЗрд▓рд╡рд╛ рдореНрдмреЗрдХреА рдПрдл рдбрдмреНрд▓реНрдпреВ рдбреА рдХреНрд▓реЗрд░реНрдХ рдкреВрд░реНрд╡рд╛ рдзрд┐рдХрд╛рд░реА рдПрдл рдбрдмреНрд▓реНрдпреВ рдбреА рдХреНрд▓реЗрд░реНрдХ рдЙрддреНрддрд░рд╛ рдзрд┐рдХрд╛рд░реА рдерд╛рдмреЛ рдореНрд╡реВрдпреЗрд▓рд╡рд╛ рдореНрдмреЗрдХреА рдЬрдиреНрдо 18 рдЬреБрд▓рд╛рдИ 1918   рдореНрд╡реЗрдЬрд╝реЛ , рдХреЗрдк рдкреНрд░рд╛рдВрдд,  рджрдХреНрд╖рд┐рдг рдЕрдлрд╝реНрд░реАрдХрд╛ рдореГрддреНрдпреБ 5 рджрд┐рд╕рдореНрдмрд░ 2013 (рдЙрдореНрд░ 95) рд╣реНрдпреВрдЯрди,  рдЬреЛрд╣рд╛рдиреНрд╕рдмрд░реНрдЧ , рджрдХреНрд╖рд┐рдг рдЕрдлрд╝реНрд░реАрдХрд╛ рдЬрдиреНрдо рдХрд╛ рдирд╛рдо рд░реЛрд▓реАрд╣реНрд▓рд▓рд╛ рдордВрдбреЗрд▓рд╛ рд░рд╛рд╖реНрдЯреНрд░реАрдпрддрд╛ рджрдХреНрд╖рд┐рдг рдЕрдлрд╝реНрд░реАрдХреА рд░рд╛рдЬрдиреАрддрд┐рдХ рджрд▓ рдЕрдлреНрд░реАрдХрди рдиреЗрд╢рдирд▓ рдХрд╛рдВрдЧреНрд░реЗрд╕ рдЬреАрд╡рди рд╕рдВрдЧреА рдПрд╡рд▓рд┐рди рдирдЯреЛрдХреЛ рдореЗрд╕ (рд╡рд┐ 1944тАУ1957; рддрд▓рд╛рдХ) рд╡рд┐рдиреА рдорджрд┐рдХрд┐рдЬрд╝реЗрд▓рд╛ (рд╡рд┐ 1958тАУ1996; рддрд▓рд╛рдХрд╝) рдЧреНрд░рд╛рд╢рд╛ рдореИрдЪрд▓ (рд╡рд┐ 1998тАУ2013; рдореГрддреНрдпреБрдкрд░реНрдпрдВрдд) рдмрдЪреНрдЪреЗ рдореЗрдбрд┐рдХрд╛ рдереЗрдордмреЗрдХрд▓ рдордВрдбреЗрд▓рд╛ рдореИрдХрдЬрд╝рд┐рд╡ рдордВрдбреЗрд▓рд╛ рдореИрдХрдЧрд╛рдереЛ рд▓реЗрд╡рд╛рдирд┐рдХрд╛ рдордВрдбреЗрд▓рд╛ рдореИрдХрдЬрд╝рд┐рд╡ рдордВрдбреЗрд▓рд╛ рдЬрд╝реЗрдирд╛рдиреА рдордВрдбреЗрд▓рд╛ рдЬрд╝рд┐рдирдЬрд╝рд┐рд╕реНрд╡рд╛ рдордВрдбреЗрд▓рд╛ рдирд┐рд╡рд╛рд╕ рд╣реНрдпреВрдЯрди рдПрд╕реНрдЯреЗрдЯ, рдЬреЛрд╣рд╛рдирд╕рдмрд░реНрдЧ, рдЧреМрдЯреЗрдВрдЧ, рджрдХреНрд╖рд┐рдг рдЕрдлрд╝реНрд░реАрдХрд╛ рд╢реИрдХреНрд╖рд┐рдХ рд╕рдореНрдмрджреНрдзрддрд╛ рдпреВрдирд┐рд╡рд░реНрд╕рд┐рдЯреА рдСрдлрд╝ рдлреЛрд░реНрдЯ рд╣реЗрд░ рдпреВрдирд┐рд╡рд░реНрд╕рд┐рдЯреА рдСрдлрд╝ рд▓рдВрджрди рдПрдХреНрд╕рдЯрд░реНрдирд▓ рд╕рд┐рд╕реНрдЯрдо рдпреВрдирд┐рд╡рд░реНрд╕рд┐рдЯреА рдСрдлрд╝ рд╕рд╛рдЙрде рдЕрдлреНрд░реАрдХрд╛ рдпреВрдирд┐рд╡рд░реНрд╕рд┐рдЯреА рдСрдлрд╝ рдж рд╡рд┐рдЯрд╡рд╛рдЯрд░рд╕реНрд░рд╛рдВрдб рдзрд░реНрдо рдИрд╕рд╛рдИ ( рдореЗрдереЛрдбрд┐рдЬрд╝реНрдо ) рд╣рд╕реНрддрд╛рдХреНрд╖рд░ рдЬрд╛рд▓рд╕реНрдерд▓ www...