+ Reply to Thread
Results 1 to 23 of 23

Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept' name

  1. #1
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept' name

    I have started a new job and took over for someone who has extensive programming knowledge. Today I was given a spreadsheet with approx 800 rows with different department data, and ended up having to copy/paste each departments' data into new files based on department number (which took a few hours). I have pasted a screen shot here of a very small example of what my file looked like. I need each departments' data to be placed in separate workbooks (not sheets within the same file) per the 3-digit Dept #, and then saved as the Dept # for the file name. I have been watching videos and reading forums for a few hours now, and am getting nowhere. Any help would be greatly appreciated! Screen Shot 2018-11-26 at 9.03.09 PM.png
    Last edited by HospitalAccountant; 11-26-2018 at 11:40 PM.

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Can you attach a small sample workbook, showing what you are trying to achieve mocked-up.

    Go Advanced -> Manage Attachments -> Upload

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .
    This is one method :

    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    I have uploaded an example
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    I uploaded an example of what I am needing to accomplish, but it did not show as a reply to your post. Thank you in advance for any help =)

  6. #6
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Thank you for this information; however, I am trying to get the information separated into new workbook files instead of sheets within the same workbook. If that cannot be achieved, your code will help me to narrow it down even more!

  7. #7
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Quote Originally Posted by HospitalAccountant View Post
    Thank you for this information; however, I am trying to get the information separated into new workbook files instead of sheets within the same workbook. If that cannot be achieved, your code will help me to narrow it down even more!
    Is it ok to assume that if column C is blank then that row is the last row of each department?
    For example cell C5 is blank, does it mean we won't find NORTH 004 dept below it?

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .
    This will save each sheet as a separate .XLSX workbook in the same location as the main workbook :

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,257

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Please Login or Register  to view this content.
    Last edited by daboho; 11-27-2018 at 07:01 AM.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17
    Quote Originally Posted by Akuini View Post
    Is it ok to assume that if column C is blank then that row is the last row of each department?
    For example cell C5 is blank, does it mean we won't find NORTH 004 dept below it?
    Yes, that is correct

  12. #12
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17
    Quote Originally Posted by Logit View Post
    .
    This will save each sheet as a separate .XLSX workbook in the same location as the main workbook :

    Please Login or Register  to view this content.
    Thank you so much! I am going to try all of the suggestions as soon as I get to work and report back.

  13. #13
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17
    Quote Originally Posted by daboho View Post
    Please Login or Register  to view this content.
    Thank you for your help! I am going to try these when I get to work and will report back!

  14. #14
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17
    Quote Originally Posted by jindon View Post
    Try
    Please Login or Register  to view this content.
    Everywhere you have a 2, say if on the file at work it was column D, I would just change the 2s to a 4? I will be trying this as soon as I get to work. Thank you so much for your help!

  15. #15
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .
    You are welcome. Let me know how it turns out.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Change all 2s to 4 except for loop counter
    i.e
    Please Login or Register  to view this content.
    This 2 should stay as it is.

  17. #17
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Logit, yours came the closest to working =) But I have gone through and tried to change the things I thought needed changed within the code, and I came up with the tabs, but no info I am going to paste a mock copy of the file from work so you can see exactly what I have. So sorry for any troubles. I learned MySQL and Java in school, but no VBA

    Once I get the new tabs created, can I add the other code to create the files at the end, or will it have to be done in 2 separate steps?

    Does anyone have videos or blogs (or know of any) where I could learn how to write/read these VBA codes? It doesn't seem tooooo hard if I could just learn the language.
    Attached Files Attached Files
    Last edited by HospitalAccountant; 11-27-2018 at 11:23 AM.

  18. #18
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .

    It appears from the new example workbook, we need to review both the NORTH and SOUTH sheets from which to copy the data to the individual new sheets ?

    Also instead of the B Column for the Dept Code, you require the D Column ?

    I'll work on those with the new workbook and if there is any other adjustments, please advise.

  19. #19
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Quote Originally Posted by Logit View Post
    .

    It appears from the new example workbook, we need to review both the NORTH and SOUTH sheets from which to copy the data to the individual new sheets ?

    Also instead of the B Column for the Dept Code, you require the D Column ?

    I'll work on those with the new workbook and if there is any other adjustments, please advise.
    Yes, we have a NORTH folder and a SOUTH folder...I do not mind at all copying the whole South tab tho and pasting to a new workbook in order to run the code separately, or I can send the files to new folders from the master folder once it's ran as I know which dept #s go where =) I have to go through and add NORTH/SOUTH to all the filenames anyhow.

    Correct, the Dept Code is column D.

    I'm sorry for all the confusion. I thought I had my sample workbook set up correctly last night at home. I can take the word TOTAL out of the last row of each Dept too if that makes it easier and I can just move it to column E so as to filter easier. I just know there is a way for this to be done each month besides copying and pasting 108 different departments data to email to each individual one. That is another duty of mine is creating an Access query to email these individual files automatically :/

  20. #20
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .
    I believe the edits will accomplish your goal. Let me know.

    If you think it would be of value, we can add the ability to delete all the sheets within the workbook except NORTH and SOUTH, prior to creating/copying to the different sheets.

    That way you won't need to manually delete those sheets before creating new.
    Attached Files Attached Files

  21. #21
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,012

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    .
    Here is the next version that deletes sheets previously created before creating new.
    Attached Files Attached Files
    Last edited by Logit; 11-27-2018 at 06:17 PM.

  22. #22
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Quote Originally Posted by Logit View Post
    .
    Here is the next version that deletes sheets previously created before creating new.
    You are amazing!!!!! The only thing is the NORTH and SOUTH departments need to be separate, but I can try and work on this =) I have got to learn this code, it would help us SO much in my department. Thank you for replying and helping me so much!

  23. #23
    Registered User
    Join Date
    11-26-2018
    Location
    Guntersville, AL
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need data from one Excel Sheet separated by 'Dept' and saved as new files with 'Dept'

    Here is the final code to do what we were looking for. Thank everyone for all of their help! Logit, you are awesome!!

    Sub parse_data()
    Dim lr As Long
    Dim ws As Worksheet
    Dim vcol, i As Integer
    Dim icol As Long
    Dim myarr As Variant
    Dim title As String
    Dim titlerow As Integer
    vcol = 3
    Set ws = Sheets("NORTH")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A5:R5"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 To lr
    On Error Resume Next
    If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
    ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
    End If
    Next
    myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
    ws.Columns(icol).Clear
    For i = 2 To UBound(myarr)
    ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
    If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
    Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
    Else
    Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
    End If
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate

    MyPath = "C:\Users\mh26702\My Documents\VBA Practice\NORTH"
    For Each sht In ThisWorkbook.Sheets
    sht.Copy
    ActiveSheet.Cells.Copy
    ActiveSheet.Cells.PasteSpecial Paste:=xlPasteValues
    ActiveSheet.Cells.PasteSpecial Paste:=xlPasteFormats
    ThisFile = sht.Name & " NORTH BUDGET " & "FY" & Format(Date, "yy")
    ActiveWorkbook.SaveAs _
    Filename:=MyPath & "\" & ThisFile & ".xlsx"
    ActiveWorkbook.Close savechanges:=False
    Next sht

    Dim xWs As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each xWs In Application.ActiveWorkbook.Worksheets
    If xWs.Name <> "NORTH" And xWs.Name <> "SOUTH" Then
    xWs.Delete
    End If
    Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

    End Sub

+ 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. Monthly Dept counts
    By sam1105 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-05-2016, 08:52 AM
  2. need a table w/ employees, dept., and counts
    By wmedina83 in forum Excel General
    Replies: 5
    Last Post: 04-29-2014, 10:21 PM
  3. Bottom Values for any given dept
    By coda1395 in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 07-09-2013, 12:47 PM
  4. [SOLVED] Dept Summary based on years of experience
    By jantonio in forum Excel General
    Replies: 2
    Last Post: 08-31-2012, 01:57 PM
  5. [SOLVED] comparing name and dept and then show job title
    By [email protected] in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-21-2012, 10:59 PM
  6. Data analysis of dates, splits & segments of dept codes
    By BRISBANEBOB in forum Excel General
    Replies: 4
    Last Post: 06-22-2009, 07:01 PM
  7. [SOLVED] Find name in list and get dept # enter dept # on work sheet
    By Jamba in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-30-2006, 06:45 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