Results 1 to 4 of 4

Excel worksheet splitting into multiple worksheets with folder save

Threaded View

  1. #1
    Registered User
    Join Date
    04-28-2014
    Location
    48483385
    MS-Off Ver
    Excel 2010
    Posts
    3

    Excel worksheet splitting into multiple worksheets with folder save

    Hello All,

    I have a decent attempt at some code that I was able to glean from a forum or two but I am having a memory issues due to the size of my population. Essentially what I need to do, is take one large worksheet and split it to many worksheets (while keeping the same format for the header row) based on unique variables found in a name field (about 150 unique variables). This code works great but then bombs due to insufficient resources at around the 10th worksheet.

    Rather than continue creating worksheets out to 150 (which I lack enough memory for anyway), I'm thinking the best bet would be to create & populate the new sheet for a unique variable, save that newly created sheet to a folder on my C Drive (which will be needed for a mail merge), delete the contents of the sheet in the macro file but not delete the sheet itself (as I think the code looks for that name before moving on), and then let the loop continue to run.

    By the time I am finished, I should have around 1 base data table, 150 empty "named" worksheets, and 150 populated saved files on my hard drive.

    The code I have now lacks:

    1. Retention of header row formatting
    2. The sheet saving and subsequent contents clearing procedure

    Finally, sample spreadsheet is attached. The forums assistance is very much appreciated as I have literally been beating my head against this wall for about 5 hours.

    Thank you in advance!

    Sub parse_data()
    Dim lr As Long
    Dim ws As Worksheet
    Dim vcol, f As Integer
    Dim icol As Long
    Dim myarr As Variant
    Dim title As String
    Dim titlerow As Integer
    vcol = 5
    Set ws = Sheets("sheet1")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A1:I1"
    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
    End Sub
    Attached Files Attached Files
    Last edited by utechtj; 04-28-2014 at 09:27 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] splitting worksheet into multiple worksheets
    By mmdecarl in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-17-2013, 02:35 PM
  2. [SOLVED] Loop through multiple files, run macro, then save as Excel workbook in a different folder
    By Peter Kallio in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-26-2013, 11:42 PM
  3. Splitting 2K worksheet into multiple worksheets
    By abmayfield in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-18-2012, 04:28 PM
  4. [SOLVED] VBA to save multiple worksheets as separate CSV files using name of worksheet
    By Yg74 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 10:55 AM
  5. VBA to save multiple worksheets as separate CSV files using name of worksheet
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 08:08 AM

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