+ Reply to Thread
Results 1 to 24 of 24

How to Split A Range of Cells Into Multiple Sheets

  1. #1
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Lightbulb How to Split A Range of Cells Into Multiple Sheets

    Hi guys:

    I have a task that bothers me since I did it manually.

    I download a weather report as CSV file from NOAA(National Oceanic and Atmospheric Administration) that contains every weather stations I select, probably at least 20 stations. Inside of the file, there is only one sheet contains every station. What I did was to manually split the each station to a new worksheet which means I also manually created 20 worksheets. Meanwhile, I needed to name the worksheets by each stations' name "manually". it's important so I double quote.

    These are the files how I started and finished. Can anyone provide any opinions?

    Thank you
    Attached Files Attached Files
    Last edited by greenarrow; 05-09-2017 at 10:47 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How to Split A Range of Cells Into Multiple Sheets


    Hi !

    Should be easy using an advanced filter …

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi greenarrow,

    Can I ask why do want to split the data as this is rarely the way to go (certainty in terms of efficiency)? You can analyse all the data in the consolidated sheet with filters and SUBTOTAL formulas for individual site(s)?

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi marc:
    so the advanced filter can split into each sheet? I tried the filter and still have to manually create and past.

  5. #5
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi Robert:
    Because I need to run the regression model for each station. then to determine which station can most likely cover the city.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: How to Split A Range of Cells Into Multiple Sheets

    Because I need to run the regression model for each station. then to determine which station can most likely cover the city.
    So you can't do that for the different ranges in the consolidated view? If not there's plenty of code that will split a consolidated view into its separate parts (tabs).

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: How to Split A Range of Cells Into Multiple Sheets

    If you must split the data, try this (noting my comments):

    Please Login or Register  to view this content.
    Regards,

    Robert
    Last edited by Trebor76; 04-27-2017 at 10:54 PM.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool As a starter …


    Quote Originally Posted by greenarrow View Post
    so the advanced filter can split into each sheet?
    I tried the filter and still have to manually create and past.
    Try this code using advanced filters :

    PHP Code: 
    Sub Demo1()
                      
    Dim Rg As RangeRc As RangeF$, C&, R&
                      
    ThisWorkbook.Path "\NOAA_NJ_04182017_Start (1).csv"
                      
    If Dir(F) = "" Then Beep: Exit Sub
                      Application
    .ScreenUpdating False
        With Workbooks
    .Open(F, , , 2)
                      
    Set Rg = .ActiveSheet.UsedRange.Columns
                     C
    & = Rg.Count 2
                 Set Rc 
    Rg.Cells(1C).Resize(2)
                          
    Rg(2).AdvancedFilter xlFilterCopy, , Rc(1), True
            
    For R& = 2 To Rc(1).End(xlDown).Row
                With 
    .Worksheets.Add(, .ActiveSheet)
                     .
    Name Left(Split(Rg.Cells(RC).Value",")(0), 31)
                          
    Rg.Range("A1:B1,F1:H1,K1:Q1").Copy .[A1]
                          
    Rg.Cells(RC).Copy Rc(2)
                          
    Rg.AdvancedFilter xlFilterCopyRc, .[A1:L1]
                     .
    Columns("A:B").AutoFit
                     
    .[A2].Select:   ActiveWindow.FreezePanes True
                End With
            Next
                      Application
    .DisplayAlerts False
                          Rg
    .Parent.Delete
                      Application
    .DisplayAlerts True
                     
    .Worksheets(1).Activate
        End With
                      Set Rg 
    Nothing:   Set Rc Nothing
                      Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  9. #9
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: As a starter …

    Quote Originally Posted by Marc L View Post

    Try this code using advanced filters :

    PHP Code: 
    Sub Demo1()
                      
    Dim Rg As RangeRc As RangeF$, C&, R&
                      
    ThisWorkbook.Path "\NOAA_NJ_04182017_Start (1).csv"
                      
    If Dir(F) = "" Then Beep: Exit Sub
                      Application
    .ScreenUpdating False
        With Workbooks
    .Open(F, , , 2)
                      
    Set Rg = .ActiveSheet.UsedRange.Columns
                     C
    & = Rg.Count 2
                 Set Rc 
    Rg.Cells(1C).Resize(2)
                          
    Rg(2).AdvancedFilter xlFilterCopy, , Rc(1), True
            
    For R& = 2 To Rc(1).End(xlDown).Row
                With 
    .Worksheets.Add(, .ActiveSheet)
                     .
    Name Left(Split(Rg.Cells(RC).Value",")(0), 31)
                          
    Rg.Range("A1:B1,F1:H1,K1:Q1").Copy .[A1]
                          
    Rg.Cells(RC).Copy Rc(2)
                          
    Rg.AdvancedFilter xlFilterCopyRc, .[A1:L1]
                     .
    Columns("A:B").AutoFit
                     
    .[A2].Select:   ActiveWindow.FreezePanes True
                End With
            Next
                      Application
    .DisplayAlerts False
                          Rg
    .Parent.Delete
                      Application
    .DisplayAlerts True
                     
    .Worksheets(1).Activate
        End With
                      Set Rg 
    Nothing:   Set Rc Nothing
                      Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Hi Marc:
    Your code worked perfectlly! But somehow it is hard for me to understand. some format you used I am still not familiar with. But thank you though!

  10. #10
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Quote Originally Posted by Trebor76 View Post
    If you must split the data, try this (noting my comments):

    Please Login or Register  to view this content.
    Regards,

    Robert
    Hi Trebor:
    Your code works perfectly as well! I will find a time to study your code. And see if there is something I don't understand! Thank you!

  11. #11
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Quote Originally Posted by Trebor76 View Post
    If you must split the data, try this (noting my comments):

    Please Login or Register  to view this content.
    Regards,

    Robert
    Quote Originally Posted by Trebor76 View Post
    Hi greenarrow,

    Can I ask why do want to split the data as this is rarely the way to go (certainty in terms of efficiency)? You can analyse all the data in the consolidated sheet with filters and SUBTOTAL formulas for individual site(s)?

    Robert
    Hi Robert:

    I just took a look at the code. There are some parts that I don't quite get it. If you have extra time, would you walk me through how you thought of the code? I want to understand how you created stetp by step. King Regard

  12. #12
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi greenarraow,

    The code is in two key parts.

    The first creates an unique list of codes from the entries in Col. A (Station Codes) of the first tab in the CSV file. This unique list (array) determines the sheets that need to be created.

    The second part loops through each item in the unique list (array), creates a new blank tab, filters the data in the first sheet based on the current item in that array (station code) and then copies the filtered (visible cells) from the first tab in the CSV file to the newly created tab and renames it using the first 31 characters (maximum character number allowed when naming a tab) of the first entry in Col. B (station name).

    HTH

    Robert

  13. #13
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Quote Originally Posted by Trebor76 View Post
    Hi greenarraow,

    The code is in two key parts.

    The first creates an unique list of codes from the entries in Col. A (Station Codes) of the first tab in the CSV file. This unique list (array) determines the sheets that need to be created.

    The second part loops through each item in the unique list (array), creates a new blank tab, filters the data in the first sheet based on the current item in that array (station code) and then copies the filtered (visible cells) from the first tab in the CSV file to the newly created tab and renames it using the first 31 characters (maximum character number allowed when naming a tab) of the first entry in Col. B (station name).

    HTH

    Robert
    Hi Robert:
    I still don't quite understand the code structure. This is more complex than I thought. Maybe it is because there are some function I haven't seen. Another question: what does it mean "HTH"?

    Regards,
    Oliver

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hope That Helps (which obviously it didn't too much )

    Maybe use Marc L's code if you're more comfortable with that solution.

  15. #15
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi greenarrow,

    This can be done with Pivot Tables.
    I created a Pivot Table and used NAME as a Report Filter.
    Under "Options" I used "Show Report Filter Page" to automatically create a Pivot Table for each of the NAMES.
    Will this work for you ?

    I have had to delete most of the "NAMED" Pivot Tablec because the file exceeded the Excel Help Forum 1Mb file size.

    Regards

    peterrc
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Quote Originally Posted by peterrc View Post
    Hi greenarrow,

    This can be done with Pivot Tables.
    I created a Pivot Table and used NAME as a Report Filter.
    Under "Options" I used "Show Report Filter Page" to automatically create a Pivot Table for each of the NAMES.
    Will this work for you ?

    I have had to delete most of the "NAMED" Pivot Tablec because the file exceeded the Excel Help Forum 1Mb file size.

    Regards

    peterrc
    Hi Peterrc:

    Sorry for the late reply!

    I thought about that but I got stuck after creating pivot tables for each station. I still need to see the detailed info though.

    GreenArrow

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: As a starter …

    Quote Originally Posted by greenarrow View Post
    Hi Marc:
    Your code worked perfectlly! But somehow it is hard for me to understand. some format you used I am still not familiar with.
    It's the standard Excel inner feature as you can do manually using an advanced filter,
    just activating Macro recorder, the beginner way …

  18. #18
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi GreenArrow,

    If you delete all the "named" Pivot Tables in the attachment in Post #15, then watch the video in the link below.
    The video shows you how to use "Show Report Filter Pages" i.e. automatically create Pivot Tables.

    Regards

    peterrc

    https://www.youtube.com/watch?v=djuLhm0roEA

  19. #19
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi Peterrc!

    Now I knew how to split the report by using the pivot option. But how can I get to what you show in the file? Mine is not showing by column, instead of by rows.
    01.PNG

  20. #20
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi GreenArrow,

    You need to change the Report Layout:-

    Pivot Table Tools > Design > Report Layout > click down arrow and select "Show In Tabular Format".

    Regards

    peterrc

  21. #21
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    that was what I tried. But I have the different format than yours.01.PNG

  22. #22
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi GreenArrow,

    You need to remove the Sub Totals:-

    Pivot Table Tools > Design > Sub Totals > click down arrow and select "Do Not Show Subtotals ".

    If you are still having issues please attach the file.

    Regards

    peterrc

  23. #23
    Registered User
    Join Date
    04-19-2017
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    30

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi P:

    I made it. Thank you for your guidance!!!!

  24. #24
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: How to Split A Range of Cells Into Multiple Sheets

    Hi GreenArrow,

    Thanks for the feedback - happy to help.
    If you are happy with the outcome please mark your thread as "Solved".

    Regards

    peterrc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding 1 to a range of cells on multiple sheets
    By dazbear in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-14-2014, 12:32 PM
  2. How to split multiple excel data /sheets into multiple PDF files
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2014, 12:25 PM
  3. Set range of cells in multiple sheets to lock after a specific date
    By miasha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2014, 07:33 PM
  4. [SOLVED] copying the same range of cells from multiple sheets
    By Chris Manion in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-18-2014, 10:55 AM
  5. Excel - save range of cells in multiple sheets to pdf with no whitespace
    By wattomusic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2013, 08:17 AM
  6. 2-Way Linking of a Range of Cells in Multiple Sheets
    By stravel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2013, 06:49 PM
  7. Copy a range of cells in multiple sheets
    By G-Star in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-14-2012, 03:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1