{"id":14806,"date":"2018-06-22T20:36:45","date_gmt":"2018-06-22T20:36:45","guid":{"rendered":"http:\/\/learnexcelmacro.com\/wp\/?p=14806"},"modified":"2023-10-20T17:59:46","modified_gmt":"2023-10-20T17:59:46","slug":"40-useful-excel-macro-examples-for-beginners-part-1-of-2","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/","title":{"rendered":"40 Useful Excel Macro [VBA] examples – Part 1 of 2"},"content":{"rendered":"

Dear Friends,<\/p>\n

Here in this article, I have tried to consolidate some most useful and more frequently used excel macro with examples. This is part 1 where I have provided 20 Excel Macros related to workbooks and worksheets. Remaining 20 Excel Macro examples will be followed in my next article – 40 Useful Excel Macro examples for Beginners – Part 2 of 2<\/a><\/em><\/strong><\/p>\n

Note:<\/strong><\/em> These are very simple yet useful and most used functions\/statements in Excel VBA. To use them, make sure that you change the Excel file path, name, sheet name, etc. change it to fit your workbook, and then run it. They should do the job which they are written for.<\/p>\n

Download a FREE Excel Workbook with all 40 Examples<\/h3>\n

At the end of the second part of this tutorial, I will publish a link to download all 40 Excel Macros collection Workbooks for FREE.<\/p>\n


\nIf you have any questions or feedback, write them in the comment below.<\/p>\n

\n

Workbook Related:<\/h3>\n

1. Create a New Excel Workbook using Excel Macro<\/a>
\n
2. Open an existing Excel Workbook using Excel Macro<\/a>
\n
3. Close a workbook without saving the changes using Excel Macro<\/a>
\n
4. Close a workbook by saving the changes using Excel Macro<\/a>
\n
5. Save or SaveAs a workbook using Excel Macro<\/a>
\n
6. Delete a workbook using Excel Macro<\/a><\/p>\n

WorkSheets related:<\/h3>\n

7. Add a new worksheet in a workbook using Excel Macro<\/a>
\n
8. Add a worksheet at a specified position using Excel Macro<\/a>
\n
9. Rename a worksheet using Excel Macro<\/a>
\n
10. Delete a worksheet using Excel Macro<\/a>
\n
11. Change the tab colour of a worksheet using Excel Macro<\/a>
\n
12. Copy a worksheet within same workbook using Excel Macro<\/a>
\n
13. Copy a worksheet as a new Workbook using Excel Macro<\/a>
\n
14. Copy a worksheet by providing sheet name of your choice using Excel Macro<\/a>
\n
15. Hide a worksheet using Excel Macro<\/a>
\n
16. Hide all worksheets except activeSheet using Excel Macro<\/a>
\n
17. Unhide a worksheet using Excel Macro<\/a>
\n
18. Unhide all worksheets in a workbook using Excel Macro<\/a>
\n
19. Check if a sheet with particular name exists in a workbook using Excel Macro<\/a>
\n
20. Sort all worksheet alphabetically using Excel Macro <\/a><\/p>\n<\/div>\n

<\/a><\/p>\n

Excel Macro to Create a new Excel workbook file<\/h2>\n

Use the following Excel VBA code to create a new Excel Workbook and save it as a given path as shown in the below code.<\/p>\n

\r\nSub CreateNewExcelWorkbook()\r\n    Dim wb As Workbook\r\n    Set wb = Workbooks.Add\r\n    ' now if you want to save this new workbook\r\n    ' save it by providing the full name of the file\r\n    wb.SaveAs \"C:\\abc\\temp.xlsx\"\r\nEnd Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to open an existing excel workbook<\/h2>\n

Refer the following Excel VBA code to open an existing excel workbook which is saved at a given path.
\nTo run the below code, do not forget to change the file path which I have provided.<\/p>\n

\r\nSub openExcelWorkbook()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\....\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    'given workbook is opened and it is referred by\r\n    ' the variable wb of type workbook\r\n    ' now you can do all the operations on wb which\r\n    ' you want to do on this workbook\r\n    \r\n    'For Example to close this workbook\r\n    wb.Close\r\nEnd Sub\r\n<\/pre>\n

Note: <\/strong> <\/em>Once you opened your workbook, you should set it to a variable of Workbook type, so that you can refer this workbook by this variable wherever you want to use in your program. <\/p>\n

<\/a><\/p>\n

Excel Macro to close a workbook with or without saving the changes<\/h2>\n

It is logical that after working on your workbook, at the end of the progrma you want to keep closing the workbook which you VBA program is using. So here is the example of closing your workbook.
\nAs you know on closing an opened workbook, there are two possibilities:<\/p>\n

1. Close the workbook without saving all the changes which are not saved yet
\n2. Close the workbook without saving any of the unsaved changes<\/p>\n

It is very simple to do using Excel VBA. While closing if set the SaveChanges<\/strong><\/em> parameter to true<\/strong><\/em> then changes will be saved and if it is set to false<\/strong><\/em> then changes will be ignored. Refer the below code…<\/p>\n

\r\nSub closeWorkbook()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\....\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    \r\n    ' For Example:\r\n    ' To close this workbook with\r\n    ' saving the changes\r\n    wb.Close SaveChanges:=True\r\n    \r\n    ' To close this workbook without\r\n    ' saving the changes\r\n    wb.Close SaveChanges:=False\r\nEnd Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to save or saveAs a workbook<\/h2>\n

As you must be aware of the difference between Save and SaveAs. It is same here in Excel vba as well.
\nIf you want to save the changes in the same file then you can use the Save statement in Excel VBA else SaveAS.
\nNote:<\/strong> For saveAs you need to provide the complete path[including file name] for the new file where you want to save it.<\/p>\n

\r\nSub saveWorkbook()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    Dim newPath As String\r\n    \r\n    fPath = \"C:\\....\\myfile.xlsx\" ' old path\r\n    newPath = \"D:\\....\\myfile1.xlsx\" ' new path\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n\r\n    ' To save your workbook at the same\r\n    ' location with same name\r\n    wb.Save\r\n    \r\n    ' to save your workbook on a different location\r\n    ' or with a different name or both\r\n    wb.SaveAs Filename:=newPath\r\n    \r\nEnd Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to delete a workbook<\/h2>\n

You can use the following example to delete a workbook.
\nNote:<\/strong> Kill statement is basically used to delete any file using Exel VBA. So you can even delete some word doc, text file etc. <\/p>\n

\r\nSub deleteFile()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    ' full path of the file which you want to delete\r\n    ' this is not necessarily to be excel file\r\n    ' it can be any file\r\n    fPath = \"C:\\....\\myfile.xlsx\"\r\n\r\n    ' this statement will delete the file\r\n    Kill PathName:=fPath\r\nEnd Sub\r\n\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to add a new worksheet in a workbook<\/h2>\n

So far in the above examples, you had seen how to deal with Workbook itself like opening, closing, saving, deleting etc.
\nNow using the below example you can add a new WorkSheet in a Workbook. To perform any such operations on a workbook, you first need to have a Workbook, therefore you will see that in all the below examples, I have first opened a workbook and assigned that Workbook to a variable wb.<\/p>\n

\r\nSub addNewSheetInAWorkbook()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\....\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' Add a new worksheet in your workbook\r\n    wb.Worksheets.Add\r\nEnd Sub\r\n\r\n<\/pre>\n

Note: <\/em><\/strong> In the above statement after .add<\/em><\/strong> there is no other parameter specified therefore new sheet will be added before the activesheet.<\/p>\n

<\/a><\/p>\n

Excel Macro to add a worksheet at a specified position<\/h2>\n

As mentioned in the above example, if do not provide the position parameter while adding a new sheet in a workbook, by default it will get added before the activeSheet.
\nNow here in the below example, I am showing you – how can you provide the position parameter while adding a new sheet.
\nRefer the comments… written inside the code.<\/p>\n

\r\n\r\nSub addNewSheetInAWorkbookAtPosition()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\....\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' Add a new worksheet in your workbook\r\n    ' Below statement will add your new sheet at first position\r\n    wb.Worksheets.Add Before:=1\r\n    ' Below statement will add your new sheet at second position\r\n    wb.Worksheets.Add After:=1\r\n    ' Below statement will add your new sheet at the end\r\n    wb.Worksheets.Add After:=Worksheets.Count\r\nEnd Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to rename a worksheet<\/h2>\n

Renaming is simply done by setting new name of the worksheet to the .Name<\/em><\/strong> property of a worksheet as shown in below code<\/p>\n

\r\nSub renameWorksheet()\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' Rename the sheet name of the 1st sheet\r\n    Set sh = wb.Worksheets(1)\r\n    sh.Name = newSheetName\r\n    \r\nEnd Sub\r\n\r\n<\/pre>\n


\n
<\/a><\/p>\n

Excel Macro to delete a worksheet<\/h2>\n

.Delete<\/em><\/strong> method of WorkSheet Object can be used to delete a worksheet.<\/p>\n

\r\nSub deleteWorksheet()\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' delete first worksheet\r\n    Set sh = wb.Worksheets(1)\r\n    ' Following statemet will launch an excel built in\r\n    ' delete confirmation popup message.\r\n    ' once you confirm it manually then this sheet would be deleted\r\n    sh.Delete\r\n\r\nEnd Sub\r\n\r\n<\/pre>\n

As mentioned in the above code’s comment section, it would display a delete confirmation popup message for your to confirm the deletion manually. Once you confirm, then deletion will take place.
\nYou can easily get rid of this popup by setting the following…<\/p>\n

\r\n    Application.DisplayAlerts = False ' to disable to delete confirmation popup\r\n    sh.Delete ' now delete the sheet\r\n    Application.DisplayAlerts = True  ' to disable to delete confirmation popup\r\n<\/pre>\n

Note:<\/strong> If you do not enable the Application.DisplayAlert flag after deleting your sheet then you would not even get this delete confirmation popup when you try to delete a sheet manually.
\nTo know more about this,
you can read my detailed article here…<\/a><\/p>\n

<\/a><\/p>\n

Excel Macro to change the tab color of a worksheet<\/h2>\n

Tab color of sheets in a workbook can be changed by .Tab.ColorIndex<\/em> <\/strong>or .Tab.Color<\/em> <\/strong>
\nColorIndex always accept a number for the color while .Color accepts RGB format of any color. You can refer these two in the below code.<\/p>\n

\r\nSub ChangeTabColor()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' delete first worksheet\r\n    Set sh = wb.Worksheets(1)\r\n    ' refer the color indexes and actual colors\r\n    ' in the below image\r\n    sh.Tab.ColorIndex = 1\r\n    \r\n    ' you can also use RGB format for defining the color code\r\n    sh.Tab.Color = RGB(255, 0, 300)\r\n    End Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to copy a worksheet within same workbook<\/h2>\n

Read the comments in the below code. Using this example, you can copy an existing worksheet in a workbook at any given postition like at the beginnig, end or second etc. positions.
\nRefer the below example:<\/p>\n

\r\n    Sub CopySheet()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' make a copy the first sheet\r\n    Set sh = wb.Worksheets(1)\r\n    ' Copy the worksheet at first position\r\n    sh.Copy Before:=Sheets(1)\r\n\r\n    ' Copy the worksheet at last position\r\n    sh.Copy After:=Sheets(Sheets.Count)\r\n    End Sub\r\n\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to copy a worksheet as a new Workbook<\/h2>\n

As you might have seen in Excel Workbook that it is possible to Copy a worksheet as a New Workbook manually.
\nThis is same thing done by using Excel Macro.<\/p>\n

Note: <\/em><\/strong> If you pass a position parameter in .Copy<\/em><\/strong> method then Worksheet will be copied within the same workbook[like in the above example] but if you skip the position parameter [like in below example] then it will be copied as a new Workbook.<\/p>\n

\r\n    Sub CopySheet()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' make a copy the first sheet\r\n    Set sh = wb.Worksheets(1)\r\n    ' Copy the worksheet as a new workbook\r\n    sh.Copy\r\n    End Sub\r\n\r\n<\/pre>\n

Note:<\/strong> If you do not use the parameters like Before or After, then .Copy will copy your worksheet as a newWorkbook with only your worksheet.<\/p>\n

If you want to copy more than one sheets to a new workbook then you can use Array to copy as shown below<\/p>\n

<\/a><\/p>\n

Excel Macro to copy multiple worksheets as a new Workbook<\/h2>\n
\r\n   Sub CopySheetAsWorkbook()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' this will copy all 3 sheets to a new workbook\r\n    wb.Worksheets(Array(\"Sheet1\", \"Sheet2\", \"Sheet3\")).Copy\r\n    End Sub\r\n\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to copy a worksheet by providing sheet name of your choice<\/h2>\n
\r\n   Sub CopySheetWithProvidedName()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    ' make a copy the first sheet\r\n    Set sh = wb.Worksheets(1)\r\n    ' Copy the worksheet as a new workbook\r\n    sh.Copy Before:=Sheets(1)\r\n    ActiveSheet.Name = \"your own name3\"\r\n    End Sub\r\n\r\n<\/pre>\n

Note:<\/strong> After making a copy of any sheet… copied sheet becomes activesheet. Therefore all you need to do is provide your own name to the activesheet.<\/p>\n

<\/a><\/p>\n

Excel Macro to hide a worksheet<\/h2>\n

Using .Visible<\/em><\/strong> property you can hide or unhide a worksheet.<\/p>\n

\r\n    Sub HideWorksheet()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    '\r\n    Set sh = wb.Worksheets(1)\r\n    ' Hide the first worksheet\r\n    sh.Visible = xlSheetHidden\r\n    End Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to unhide a worksheet<\/h2>\n

Using .Visible<\/em><\/strong> property you can hide or unhide a worksheet.<\/p>\n

\r\n    Sub HideWorksheet()\r\n\r\n    Dim wb As Workbook\r\n    Dim sh As Worksheet\r\n    \r\n    Dim newSheetName As String\r\n    newSheetName = \"March\"\r\n   \r\n    Dim fPath As String\r\n    \r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    '\r\n    Set sh = wb.Worksheets(1)\r\n    ' unhide the first worksheet\r\n    sh.Visible = xlSheetVisible\r\n    End Sub\r\n<\/pre>\n


\n
<\/a><\/p>\n

Excel Macro to hide all worksheets except activeSheet<\/h2>\n
\r\n    Sub HideAllWorksheets()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    For Each Sheet In wb.Worksheets\r\n        If Sheet.Name <> ActiveSheet.Name Then\r\n            Sheet.Visible = False\r\n        End If\r\n    Next\r\n    End Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to unhide all worksheets in a workbook<\/h2>\n
\r\n    Sub UnhideAllWorksheets()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    For Each Sheet In wb.Worksheets\r\n        If Sheet.Name <> ActiveSheet.Name Then\r\n            Sheet.Visible = True\r\n        End If\r\n    Next\r\n    End Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to check if a sheet with particular name exists in a workbook<\/h2>\n
\r\n    Sub CheckIfSheetExists()\r\n    Dim wb As Workbook\r\n    Dim fPath As String\r\n    Dim sheetExists As Boolean\r\n    sheetExists = False\r\n    fPath = \"C:\\Users\\vmishra\\Desktop\\myfile.xlsx\"\r\n    Set wb = workbooks.Open(Filename:=fPath)\r\n    For Each Sheet In wb.Worksheets\r\n        If Sheet.Name = \"SheetName To Search\" Then\r\n            sheetExists = True\r\n            Exit For\r\n        End If\r\n    Next\r\n    If sheetExists Then\r\n        MsgBox \"Yes, SheetName To Search exists in the workbook\"\r\n    End If\r\n    \r\n    End Sub\r\n<\/pre>\n

<\/a><\/p>\n

Excel Macro to sort all worksheet alphabetically<\/h2>\n

If you want to sort all the worksheets in your workbook in alphabetical order, then copy paste following code in any module and run it. <\/p>\n

\r\nSub SortSheetNames()\r\n    ' Sort all the sheets alphabetically\r\n    Dim i As Integer\r\n    Dim j As Integer\r\n    Dim totalSheets As Integer\r\n    totalSheets = Sheets.Count\r\n    For i = 1 To totalSheets - 1\r\n        For j = i + 1 To totalSheets\r\n            If Sheets(j).Name < Sheets(i).Name Then\r\n                Sheets(j).Move Before:=Sheets(i)\r\n            End If\r\n        Next j\r\n    Next i\r\n    Application.ScreenUpdating = True\r\nEnd Sub\r\n<\/pre>\n
\nHow did you find this collection of 40 Excel Macro examples? Did you find them useful to you? Provide your feedback about this. I will write more of such articles with more and more useful and simple Excel VBA Macro examples. Click here to read the remaining 20 Useful Excel Macros collection in the next part.<\/a><\/em><\/strong><\/p>\n

Download your Excel File with all 40 Useful Macro Collection<\/h2>\n\n<\/div>\n<\/span>","protected":false},"excerpt":{"rendered":"

Dear Friends, Here in this article, I have tried to consolidate some most useful and more frequently used excel macro with examples. This is part 1 where I have provided 20 Excel Macros related to workbooks and worksheets. Remaining 20 Excel Macro examples will be followed in my next article – 40 Useful Excel Macro […]<\/p>\n","protected":false},"author":45,"featured_media":242634,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1679,1675,1678,1682],"tags":[],"class_list":["post-14806","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-macro-beginner","category-excel-macro-for-beginners","category-interesting-vba-functions","category-popular-articles"],"yoast_head":"\n40 Useful Excel Macro [VBA] examples - Part 1 of 2 - Let's excel in Excel<\/title>\n<meta name=\"description\" content=\"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"40 Useful Excel Macro [VBA] examples - Part 1 of 2\" \/>\n<meta property=\"og:description\" content=\"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-22T20:36:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-20T17:59:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"538\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"40 Useful Excel Macro [VBA] examples – Part 1 of 2\",\"datePublished\":\"2018-06-22T20:36:45+00:00\",\"dateModified\":\"2023-10-20T17:59:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\"},\"wordCount\":1511,\"commentCount\":16,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png\",\"articleSection\":[\"Excel Macro Beginner\",\"Excel Macro Tutorial\",\"Interesting VBA Functions\",\"Popular Articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\",\"name\":\"40 Useful Excel Macro [VBA] examples - Part 1 of 2 - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png\",\"datePublished\":\"2018-06-22T20:36:45+00:00\",\"dateModified\":\"2023-10-20T17:59:46+00:00\",\"description\":\"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png\",\"width\":800,\"height\":538,\"caption\":\"Top 40 Useful Excel VBA Code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro Beginner\",\"item\":\"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"40 Useful Excel Macro [VBA] examples – Part 1 of 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"40 Useful Excel Macro [VBA] examples - Part 1 of 2 - Let's excel in Excel","description":"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/","og_locale":"en_US","og_type":"article","og_title":"40 Useful Excel Macro [VBA] examples - Part 1 of 2","og_description":"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work","og_url":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2018-06-22T20:36:45+00:00","article_modified_time":"2023-10-20T17:59:46+00:00","og_image":[{"width":800,"height":538,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png","type":"image\/png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"40 Useful Excel Macro [VBA] examples – Part 1 of 2","datePublished":"2018-06-22T20:36:45+00:00","dateModified":"2023-10-20T17:59:46+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/"},"wordCount":1511,"commentCount":16,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png","articleSection":["Excel Macro Beginner","Excel Macro Tutorial","Interesting VBA Functions","Popular Articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/","url":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/","name":"40 Useful Excel Macro [VBA] examples - Part 1 of 2 - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png","datePublished":"2018-06-22T20:36:45+00:00","dateModified":"2023-10-20T17:59:46+00:00","description":"Top 40 useful Excel VBA code for Beginners. 40 Most frequently used Excel VBA examples. Excel macro tutorials for beginners. 40 most used Excel Macro examples for Excel VBA beginners. 40 Excel VBA examples to improve your productivity at work","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#primaryimage","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2018\/06\/40-useful-excel-vb-code-2-1.png","width":800,"height":538,"caption":"Top 40 Useful Excel VBA Code"},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2018\/06\/40-useful-excel-macro-examples-for-beginners-part-1-of-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro Beginner","item":"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/"},{"@type":"ListItem","position":3,"name":"40 Useful Excel Macro [VBA] examples – Part 1 of 2"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/14806"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=14806"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/14806\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media\/242634"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=14806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=14806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=14806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}