{"id":5276,"date":"2024-02-08T11:26:08","date_gmt":"2024-02-08T11:26:08","guid":{"rendered":"https:\/\/powergi.net\/?p=5276"},"modified":"2026-06-11T20:12:01","modified_gmt":"2026-06-11T20:12:01","slug":"how-to-split-one-excel-sheet-into-multiple-files-using-macro","status":"publish","type":"post","link":"https:\/\/powergi.net\/es\/blog\/how-to-split-one-excel-sheet-into-multiple-files-using-macro\/","title":{"rendered":"Excel VBA macro to split sheet contents into multiple files"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"5276\" class=\"elementor elementor-5276\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-df1155e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"df1155e\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3382d2f\" data-id=\"3382d2f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-dfa5a46 elementor-widget elementor-widget-text-editor\" data-id=\"dfa5a46\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">We usually talk about Power Platform here, but this time we bring you some awesome <\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Visual_Basic_for_Applications\" target=\"_blank\" rel=\"noopener\"><b>VBA<\/b><\/a><span style=\"font-weight: 400;\"> piece of code that you use to split the content of an Excel worksheet into multiple files, based on N number of rows \u2013 created by our colleague <\/span><a href=\"https:\/\/www.linkedin.com\/in\/jeymi-aguilar-03b817247\/\" target=\"_blank\" rel=\"noopener\"><b>Jeymi Membre\u00f1o<\/b><\/a><span style=\"font-weight: 400;\">.<\/span><\/p><div id=\"seology-cta-1\">\t\t<div data-elementor-type=\"section\" data-elementor-id=\"7267\" class=\"elementor elementor-7267\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-7e3f164 e-con-full e-flex e-con e-parent\" data-id=\"7e3f164\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"background_background\":\"classic\",\"jet_parallax_layout_list\":[]}'>\n\t\t<div class=\"elementor-element elementor-element-9078c9f e-con-full e-flex e-con e-child\" data-id=\"9078c9f\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b99949 elementor-widget elementor-widget-heading\" data-id=\"7b99949\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Convierte tus ideas en soluciones digitales<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e61db5 elementor-widget elementor-widget-heading\" data-id=\"8e61db5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Nuestro equipo te gu\u00eda paso a paso para crear aplicaciones personalizadas en Power Platform.<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-a578907 e-flex e-con-boxed e-con e-child\" data-id=\"a578907\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e8c827b elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"e8c827b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"#ctc_chat\">\n\t\t\t<i aria-hidden=\"true\" class=\"fab fa-whatsapp\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d834237 elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"d834237\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"https:\/\/powergi.net\/es\/contact\/\">\n\t\t\t<i aria-hidden=\"true\" class=\"far fa-envelope\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<\/div><p><span style=\"font-weight: 400;\">Say goodbye to manual splitting and hello to automation using VBA in Excel. If you\u2019re working with <\/span><a href=\"https:\/\/powergi.net\/es\/power-apps-consulting-services\/\"><b>PowerApps consulting services<\/b><\/a><span style=\"font-weight: 400;\">, this can be a great addition to your automation toolkit.<\/span><\/p><p><span style=\"font-weight: 400;\">If you have a file with 550 rows and you want to get separate files for each batch of 100 rows, this code will return 6 files.\u00a0<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-477feab elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"477feab\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-be2ada1\" data-id=\"be2ada1\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-79e12b9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"79e12b9\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f4e3e82\" data-id=\"f4e3e82\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-efc67a7 elementor-widget elementor-widget-heading\" data-id=\"efc67a7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Step 1. Let\u2019s Define Some Variables<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-cbf4582 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"cbf4582\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9721acb\" data-id=\"9721acb\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5ccc1a0 elementor-widget elementor-widget-code-highlight\" data-id=\"5ccc1a0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly class=\"language-javascript\">\n\t\t\t\t\t<xmp>  ' Variables\r\n    Dim ws As Worksheet\r\n    Dim totalRows As Long\r\n    Dim rowsPerFile As Long\r\n    Dim totalFiles As Long\r\n    Dim i As Long\r\n    Dim startingRow As Long\r\n    Dim endingRow As Long\r\n    Dim newWorkbook As Workbook  \r\n    ' Set Worksheet\r\n    Set ws = ThisWorkbook.Sheets(\"Sheet1\")  \r\n    ' Number of rows per file\r\n    rowsPerFile = 100    \r\n    ' Set starting row. We have a header row so we want to start copying and pasting from this row.\r\n    startingRow = 2\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-10918fe elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"10918fe\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-09570c4\" data-id=\"09570c4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c4aca3b elementor-widget elementor-widget-text-editor\" data-id=\"c4aca3b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2><b>Step 2. Calculate The Number Of Rows In Worksheet And The Number Of Files That The Code Will Return<\/b><\/h2>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-29e6a36 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"29e6a36\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9e5a07d\" data-id=\"9e5a07d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-87db3e6 elementor-widget elementor-widget-code-highlight\" data-id=\"87db3e6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly class=\"language-javascript\">\n\t\t\t\t\t<xmp> ' Get number of rows in file\r\n    totalRows = ws.Cells(ws.Rows.Count, \"A\").End(xlUp).Row\r\n    ' Calculate the number of files needed \u2013 here we use the result from previous line and the rowsPerFile variable to calculate.\r\n    totalFiles = Application.WorksheetFunction.Ceiling(totalRows \/ rowsPerFile, 1)\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3c5e76f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3c5e76f\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-849ce84\" data-id=\"849ce84\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4500b7f elementor-widget elementor-widget-text-editor\" data-id=\"4500b7f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2><b>Step 3. Copy Data And Create Each Individual File<\/b><\/h2>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-c145ffd elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c145ffd\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0e98274\" data-id=\"0e98274\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-120c77b elementor-widget elementor-widget-code-highlight\" data-id=\"120c77b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly class=\"language-javascript\">\n\t\t\t\t\t<xmp>  ' Loop to create files\r\n    For i = 1 To totalFiles\r\n        ' Calculate row range for each file\r\n        endingRow = startingRow + rowsPerFile - 1\r\n        If endingRow &gt; totalRows Then\r\n            endingRow = totalRows\r\n        End If        \r\n        ' Create new book\r\n        Set newWorkbook = Workbooks.Add        \r\n        ' Copy header row in new file\r\n        ws.Rows(1).EntireRow.Copy newWorkbook.Sheets(1).Rows(1)\r\n        ' Copy rows to new file\r\n        ws.Rows(startingRow &amp; \":\" &amp; endingRow).EntireRow.Copy newWorkbook.Sheets(1).Rows(2)      \r\n        ' Change workseet name\r\n        newWorkbook.Sheets(1).Name = ws.Name       \r\n        ' Save file in the same workbook path as current file \u2013 files will be created with the word \u201cFile\u201d as prefix and then the number of file.\r\n        newWorkbook.SaveAs ThisWorkbook.Path &amp; \"\\\" &amp; \"File\" &amp; i &amp; \".xlsx\" '        \r\n        ' Close new book\r\n        newWorkbook.Close SaveChanges:=False        \r\n        ' Update starting row for next file\r\n        startingRow = endingRow + 1\r\n    Next i    \r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-eed5893 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eed5893\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4bb6ab6\" data-id=\"4bb6ab6\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6047ff8 elementor-widget elementor-widget-text-editor\" data-id=\"6047ff8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">That\u2019s it!\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">Just replace the <\/span><b>rowsPerFile<\/b><span style=\"font-weight: 400;\"> variable if you need more or less than 100 rows to be copied over to the individual files.<\/span><\/p><div id=\"seology-cta-2\">\t\t<div data-elementor-type=\"section\" data-elementor-id=\"7280\" class=\"elementor elementor-7280\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-7e3f164 e-con-full e-flex e-con e-parent\" data-id=\"7e3f164\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"background_background\":\"classic\",\"jet_parallax_layout_list\":[]}'>\n\t\t<div class=\"elementor-element elementor-element-9078c9f e-con-full e-flex e-con e-child\" data-id=\"9078c9f\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b99949 elementor-widget elementor-widget-heading\" data-id=\"7b99949\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Automatiza las tareas que te ralentizan<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8e61db5 elementor-widget elementor-widget-heading\" data-id=\"8e61db5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Libere el tiempo de su equipo y conc\u00e9ntrese en el trabajo estrat\u00e9gico con la automatizaci\u00f3n digital y rob\u00f3tica.<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-a578907 e-flex e-con-boxed e-con e-child\" data-id=\"a578907\" data-element_type=\"container\" data-e-type=\"container\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e8c827b elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"e8c827b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"#ctc_chat\">\n\t\t\t<i aria-hidden=\"true\" class=\"fab fa-whatsapp\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d834237 elementor-view-stacked elementor-shape-circle elementor-widget elementor-widget-icon\" data-id=\"d834237\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<a class=\"elementor-icon\" href=\"https:\/\/powergi.net\/es\/contact\/\">\n\t\t\t<i aria-hidden=\"true\" class=\"far fa-envelope\"><\/i>\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<\/div><p>Streamlining your tasks with automation is essential, especially when paired with <a href=\"https:\/\/powergi.net\/es\/microsoft-power-platform-consulting-services\/\"><strong>PowerApps consulting services<\/strong><\/a>. Our expertise ensures that you harness the full potential of automation, simplifying complex processes and enhancing efficiency.<\/p><h3><b>This Is How The Final Code Looks<\/b><\/h3>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-6de040f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6de040f\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-646dfef\" data-id=\"646dfef\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a9e2f74 elementor-widget elementor-widget-code-highlight\" data-id=\"a9e2f74\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly class=\"language-javascript\">\n\t\t\t\t\t<xmp>Sub SplitSheetContent()\r\n    ' Variables\r\n    Dim ws As Worksheet\r\n    Dim totalRows As Long\r\n    Dim rowsPerFile As Long\r\n    Dim totalFiles As Long\r\n    Dim i As Long\r\n    Dim startingRow As Long\r\n    Dim endingRow As Long\r\n    Dim newWorkbook As Workbook\r\n    ' Set Worksheet\r\n    Set ws = ThisWorkbook.Sheets(\"Events\")    \r\n    ' Number of rows per file\r\n    rowsPerFile = 100\r\n    ' Get number of rows in file\r\n    totalRows = ws.Cells(ws.Rows.Count, \"A\").End(xlUp).Row    \r\n    ' Calculate the number of files needed\r\n    totalFiles = Application.WorksheetFunction.Ceiling(totalRows \/ rowsPerFile, 1)  \r\n    ' Init variables\r\n    startingRow = 2   \r\n    ' Loop to create files\r\n    For i = 1 To totalFiles\r\n        ' Calculate row range for each file\r\n        endingRow = startingRow + rowsPerFile - 1\r\n        If endingRow &gt; totalRows Then\r\n            endingRow = totalRows\r\n        End If      \r\n        ' Create new book\r\n        Set newWorkbook = Workbooks.Add  \r\n        ' Copy header row in new file\r\n        ws.Rows(1).EntireRow.Copy newWorkbook.Sheets(1).Rows(1)\r\n        ' Copy rows to new file\r\n        ws.Rows(startingRow &amp; \":\" &amp; endingRow).EntireRow.Copy newWorkbook.Sheets(1).Rows(2)\r\n        ' Change workseet name\r\n        newWorkbook.Sheets(1).Name = ws.Name\r\n        ' Save file in the same workbook path as current file\r\n        newWorkbook.SaveAs ThisWorkbook.Path &amp; \"\\\" &amp; \"Reporte00\" &amp; i &amp; \".xlsx\" ' \r\n        ' Close new book\r\n        newWorkbook.Close SaveChanges:=False\r\n        ' Update starting row for next file\r\n        startingRow = endingRow + 1\r\n    Next i   \r\nEnd Sub\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f051d17 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f051d17\" data-element_type=\"section\" data-e-type=\"section\" data-settings='{\"jet_parallax_layout_list\":[]}'>\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-70d05f3\" data-id=\"70d05f3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>We usually talk about Power Platform here, but this time we bring you some awesome VBA piece of code that you use to split the content of an Excel worksheet into multiple files, based on N number of rows \u2013 created by our colleague Jeymi Membre\u00f1o. From vision to execution Whether you&#8217;re just starting or [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":5298,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"glossary_letter":"","footnotes":""},"categories":[172],"tags":[127,128,129,124],"class_list":["post-5276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dpa","tag-excel-macro","tag-excel-macros-with-vba","tag-power-gi","tag-power-platform"],"glossary_letter":"","rank_math_title":"Excel Macro | VBA | Power GI","rank_math_description":"Unlock the potential of Excel macros with VBA tailored by Power GI. Streamline tasks, productivity, and simplify data management effortlessly.","rank_math_focus_keyword":"Excel","_links":{"self":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts\/5276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/comments?post=5276"}],"version-history":[{"count":1,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts\/5276\/revisions"}],"predecessor-version":[{"id":13555,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/posts\/5276\/revisions\/13555"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/media\/5298"}],"wp:attachment":[{"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/media?parent=5276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/categories?post=5276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powergi.net\/es\/wp-json\/wp\/v2\/tags?post=5276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}