How To Split data in a sheet by the specific number of rows using VBA in Excel?
Tags: tosplitdatainasheetb, vbamacros
Published: 2021-09-29 09:13:30

---
title: How To Split data in a sheet by the specific number of rows using VBA in Excel?
published: true
date: 2021-09-27 09:21:31 UTC
tags: ToSplitDataInASheetB,VBAMacros
canonical_url: https://geekexcel.com/how-to-split-data-in-a-sheet-by-the-specific-number-of-rows-using-vba-in-excel/
---

In this blog post, we are going to see how to  **split data in a sheet by the specific number of rows** using VBA in Microsoft Excel. Let’s get into this article!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to **create a sample data** in the Microsoft Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-43.png)<figcaption>Sample data</figcaption>

- Then, you have to **split this data in multiple sheets**.
- Now, you need to create one **main sheet** with **sample data** in Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Main-Sheet.png)<figcaption>Main sheet</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit
Sub SplitDataToMultipleSheets()
'Declaring variables
Dim LastRow As Long, n As Long, CntRows As Long
Dim LastColumn As Integer
'Getting count of number of rows required in one sheet
CntRows = CInt(Sheets("Main").TextBox1.Value)
'Disabling screen updates
Application.ScreenUpdating = False
With Sheets("RawData")
    'Getting row number and column number of last cell
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    LastColumn = .Range("A1").SpecialCells(xlCellTypeLastCell).Column
    'Looping through data in the sheet
    For n = 1 To LastRow Step CntRows 
        'Adding new worksheet
        Sheets.Add after:=Sheets(Sheets.Count)
        'Copying data to new worksheet
        .Range("A" & n).Resize(CntRows, LastColumn).Copy Range("A1")
    Next n  
    .Activate
End With
'Enabling screen updates
Application.ScreenUpdating = True
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-81.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-50.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive **new sheets inserted** , with **each sheet** having **25 records**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-41.png)<figcaption>Output</figcaption>

## Verdict

In the above article, you can learn the simple steps to  **split data in a sheet by the specific number of rows** using VBA in Microsoft Excel. Kindly, share your **feedback** in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

**Read Also:**

- **[How to Change Font Color in Microsoft Excel 2007?](https://geekexcel.com/how-to-change-font-color-in-microsoft-excel-2007/)**
- **[Excel Formulas to Count specific word in a range ~ Easy Tutorial!!](https://geekexcel.com/excel-formulas-to-count-specific-words-in-a-range/)**
- **[Excel Formulas to Get the Last Word of a Text String ~ Quick Method!!](https://geekexcel.com/excel-formulas-to-get-the-last-word-of-the-text-string/)**
- **[Count the Times a Word Appears in a Cell or a Range in Excel Office 365!!](https://geekexcel.com/count-the-times-a-word-appears-in-a-cell-or-a-range-in-excel-office-365/)**
- **[Excel Formulas to Remove the Last Word ~ Easy Tutorial!!](https://geekexcel.com/excel-formulas-to-remove-the-last-word-easy-tutorial/)**