Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:46:32+00:00 2026-06-13T16:46:32+00:00

I have a large data set with an identifier attributed to each row. There

  • 0

I have a large data set with an identifier attributed to each row. There around 10 different identifiers for the whole dataset but this can be variable. The aim is to break the main dataset up into individual worksheets for each group of identifiers. I have written this code below which does the job but seems very clunky with a loop to make all the worksheets and another to go through each row.

    ...

    '--> Get list of Area Codes
    ws1.Range("N:N").Copy
    Set TempWS = Sheets.Add
    With TempWS
        With .Range("A:A")
            .PasteSpecial
            .AdvancedFilter xlFilterInPlace, Unique:=True
            .SpecialCells(xlCellTypeVisible).Copy
        End With
        .Range("B:B").PasteSpecial
        .ShowAllData
        .Range("A:A").Delete
        .Rows(1).Delete
        tmpLR = .Range("A" & Rows.Count).End(xlUp).Row + 1
    End With

    '--> Create Worksheet for Each Code
    i = 1
    Do Until i = tmpLR
    Set ws = Sheets.Add
    ws.Name = TempWS.Cells(i, 1).Text
    ws1.Range("A1").EntireRow.Copy
    ws.Rows("1:1").PasteSpecial
    i = i + 1
    Loop

    TempWS.Delete

    '--> Break Up Main Data Sheet into Area Code Sheets
    Set rng = ws1.Range("N2:N" & LRws1)
    For Each c In rng
        shname = c.Text
        c.EntireRow.Copy
        Set oWS = Sheets(shname)
        oLR = oWS.Range("A" & Rows.Count).End(xlUp).Row + 1
        oWS.Rows(oLR).PasteSpecial
    Next

    ...

Is there a more efficient way of completing this process instead of looping multiple times?

I also noticed that with this line c.entirerow.copy it is not possible to use a cut instead of copy, what’s the reason for this?

Format is like this:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:46:34+00:00Added an answer on June 13, 2026 at 4:46 pm

    if I can read well, the original main table would look something like this in a simplified form:

    HEADER1          HEADER2          HEADER3          AREACODES
    Area1_Value1     Area1_Value2     Area1_Value3     Area1
    Area2_Value1     Area2_Value2     Area2_Value3     Area2
    Area3_Value1     Area3_Value2     Area3_Value3     Area3 
    

    You want to create a new sheet for each of the Areacodes (named Area1,2,3) and fill in the headers + corresponding line.
    The code written below is merely a framework on the table form that I have drawn, you can customize this code the way you want it.

    Sub Area_Codes()
    
    Dim oRange                  As Range
    Dim oRange_Headers          As Range
    Dim vArray_Headers          As Variant
    Dim oRange_Area             As Range
    Dim vArray_Area             As Variant
    Dim oRange_Area_Dest        As Range
    
    Dim lRange_Rows             As Long
    Dim iRange_Cols             As Integer
    Dim vArray                  As Variant
    
    Dim oSheet_Main             As Excel.Worksheet
    Dim oSheet                  As Excel.Worksheet
    Dim lUse_Row                As Long
    
    Dim lCnt                    As Long
    Dim lCnt_B                  As Long
    Dim bExists                 As Boolean
    
    
    Const AreaCodes_Col = 4
    
    
    Set oSheet_Main = ThisWorkbook.Sheets(1)
    Set oRange = oSheet_Main.UsedRange
    lRange_Rows = oRange.Rows.Count
    iRange_Cols = oRange.Columns.Count
    ReDim vArray(1 To lRange_Rows, 1 To iRange_Cols)
    vArray = oRange
    
    'load your headers into a separate range 
    Set oRange_Headers = oRange.Rows(1)
    'Set dimensions of the array equal to dimensions of the range and load range into memory (array) 
    ReDim vArray_Headers(1 To 1, 1 To iRange_Cols)
    vArray_Headers = oRange
    'Clear the range from memory 
    Set oRange_Headers = Nothing
    
    'Start as from row 2 (Row 1 = header) 
    For lCnt = 2 To lRange_Rows
        'Clear the row containing the area code info from memory - reload on every loop 
        Set oRange_Area = Nothing
        'Exceptional activate
        oSheet_Main.Activate
        'Set row of Area + load into memory 
        Set oRange_Area = oSheet_Main.Range(Cells(lCnt, 1), Cells(lCnt, iRange_Cols))
        ReDim vArray_Area(1 To 1, 1 To iRange_Cols)
        vArray_Area = oRange_Area
    
        'Check if sheet exists, load result into boolean value 
        bExists = False
        For Each oSheet In ThisWorkbook.Sheets
            If oSheet.Name = vArray(lCnt, AreaCodes_Col) Then
                bExists = True
            End If
        Next oSheet
    
        'Add sheet if sheet doesn't exist + name 
        Set oSheet = Nothing
        If Not bExists Then
            Set oSheet = Sheets.Add
            oSheet.Name = (vArray(lCnt, AreaCodes_Col))
        Else
            'Define sheet object if sheet already exists 
            Set oSheet = ThisWorkbook.Sheets(vArray(lCnt, AreaCodes_Col))
            oSheet.Activate
        End If
    
        'Define destination range of headers; You could name this otherwise, to avoid confusion 
        Set oRange_Headers = oSheet.Range(Cells(1, 1), Cells(1, iRange_Cols))
        oRange_Headers = vArray_Headers
    
        'Check last row used, +1 sets the last row + 1 -> the destination row         
        lUse_Row = oSheet.UsedRange.Rows.Count + 1
        Set oRange_Area_Dest = oSheet.Range(Cells(lUse_Row, 1), Cells(lUse_Row, iRange_Cols))
        'Fill in the destination row 
        oRange_Area_Dest = vArray_Area
    Next lCnt
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data set and I want to write a custom merge
I have a large data set that I'm working with in excel. About 1000+
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I have a very large possible data set that I am trying to visualize
I have a large real 1-d data set called r. I would like plot:
I have a large set of data that is generated from a web service
I have a large set of data which I access via a generator/iterator. While
Basically I have a large set of data in excel, and I was wondering
I have implemented paging for a large set of data in an application by
I have situation where a user can manipulate a large set of data (presented

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.