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

рдиेрд▓्рд╕рди рдоंрдбेрд▓ा

рдордИ 2008 рдоें рдоंрдбेрд▓ा рджрдХ्рд╖िрдг рдЕрдл्рд░ीрдХा рдХे рд░ाрд╖्рдЯ्рд░рдкрддि рдкрдж рдмрд╣ाрд▓ 10 рдордИ 1994 – 14 рдЬूрди 1999 рд╕рд╣ाрдпрдХ рдеाрдмो рдо्рд╡ूрдпेрд▓рд╡ा рдо्рдмेрдХी рдПрдл рдбрдм्рд▓्рдпू рдбी рдХ्рд▓ेрд░्рдХ рдкूрд░्рд╡ा рдзिрдХाрд░ी рдПрдл рдбрдм्рд▓्рдпू рдбी рдХ्рд▓ेрд░्рдХ рдЙрдд्рддрд░ा рдзिрдХाрд░ी рдеाрдмो рдо्рд╡ूрдпेрд▓рд╡ा рдо्рдмेрдХी рдЬрди्рдо 18 рдЬुрд▓ाрдИ 1918   рдо्рд╡ेрдЬ़ो , рдХेрдк рдк्рд░ांрдд,  рджрдХ्рд╖िрдг рдЕрдл़्рд░ीрдХा рдоृрдд्рдпु 5 рджिрд╕рдо्рдмрд░ 2013 (рдЙрдо्рд░ 95) рд╣्рдпूрдЯрди,  рдЬोрд╣ाрди्рд╕рдмрд░्рдЧ , рджрдХ्рд╖िрдг рдЕрдл़्рд░ीрдХा рдЬрди्рдо рдХा рдиाрдо рд░ोрд▓ीрд╣्рд▓рд▓ा рдоंрдбेрд▓ा рд░ाрд╖्рдЯ्рд░ीрдпрддा рджрдХ्рд╖िрдг рдЕрдл़्рд░ीрдХी рд░ाрдЬрдиीрддिрдХ рджрд▓ рдЕрдл्рд░ीрдХрди рдиेрд╢рдирд▓ рдХांрдЧ्рд░ेрд╕ рдЬीрд╡рди рд╕ंрдЧी рдПрд╡рд▓िрди рдирдЯोрдХो рдоेрд╕ (рд╡ि 1944–1957; рддрд▓ाрдХ) рд╡िрдиी рдорджिрдХिрдЬ़ेрд▓ा (рд╡ि 1958–1996; рддрд▓ाрдХ़) рдЧ्рд░ाрд╢ा рдоैрдЪрд▓ (рд╡ि 1998–2013; рдоृрдд्рдпुрдкрд░्рдпंрдд) рдмрдЪ्рдЪे рдоेрдбिрдХा рдеेрдордмेрдХрд▓ рдоंрдбेрд▓ा рдоैрдХрдЬ़िрд╡ рдоंрдбेрд▓ा рдоैрдХрдЧाрдеो рд▓ेрд╡ाрдиिрдХा рдоंрдбेрд▓ा рдоैрдХрдЬ़िрд╡ рдоंрдбेрд▓ा рдЬ़ेрдиाрдиी рдоंрдбेрд▓ा рдЬ़िрдирдЬ़िрд╕्рд╡ा рдоंрдбेрд▓ा рдиिрд╡ाрд╕ рд╣्рдпूрдЯрди рдПрд╕्рдЯेрдЯ, рдЬोрд╣ाрдирд╕рдмрд░्рдЧ, рдЧौрдЯेंрдЧ, рджрдХ्рд╖िрдг рдЕрдл़्рд░ीрдХा рд╢ैрдХ्рд╖िрдХ рд╕рдо्рдмрдж्рдзрддा рдпूрдиिрд╡рд░्рд╕िрдЯी рдСрдл़ рдлोрд░्рдЯ рд╣ेрд░ рдпूрдиिрд╡рд░्рд╕िрдЯी рдСрдл़ рд▓ंрджрди рдПрдХ्рд╕рдЯрд░्рдирд▓ рд╕िрд╕्рдЯрдо рдпूрдиिрд╡рд░्рд╕िрдЯी рдСрдл़ рд╕ाрдЙрде рдЕрдл्рд░ीрдХा рдпूрдиिрд╡рд░्рд╕िрдЯी рдСрдл़ рдж рд╡िрдЯрд╡ाрдЯрд░рд╕्рд░ांрдб рдзрд░्рдо рдИрд╕ाрдИ ( рдоेрдеोрдбिрдЬ़्рдо ) рд╣рд╕्рддाрдХ्рд╖рд░ рдЬाрд▓рд╕्рдерд▓ www .nelsonmandela .org рдиेрд▓्рд╕рди рд░ोрд▓ीрд╣्рд▓рд▓ा рдоंрдбेрд▓ा  ( рдЦ़ोрд╕ा : N

Unsend Sent Messages

Unsend Sent Messages_ This is one of the most useful Gmail tricks. Go to   Settings  >  General tab  and check off “ Enable Undo Send .” You can also set the cancellation period as 5, 10, 20 or 30 seconds. Click on  Save Changes  at the bottom of the page. Next time when you send a message, you will see an  Undo  option in yellow below the search bar. You can click on it to unsend the message, and then you can edit it or discard it.