+ Reply to Thread
Results 1 to 5 of 5

Need to Split Data into sections and sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Need to Split Data into sections and sheets

    Hi All,

    Can Someone help, ive been trying to figure out how i can use VBA to Split large number of data into sections and then into different sheets then export to text file, so i have large amount of data but it always starts at cell E5 but i want to cut 50 rows and 50 column of the data and put it into a new sheet then exports as TXT file, finally i want to repeat this until no data is left in the original work sheet.

    I could have 100s or 1000s rows and columns filled but i need to be able to break it down to chunks.

    Any Ideas?
    Last edited by shelim481; 08-30-2018 at 05:18 AM.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Need to Split Data into sections and sheets

    ive been trying to figure out how i can use VBA
    That being the case you might consider having a Mod/Admin move your thread over to that sub-forum. (Please don't do this yourself. That's called double-posting.)
    Dave

  3. #3
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Re: Need to Split Data into sections and sheets

    I should mention in the txt file, it needs to have no speech marks, and each text file should be named in order, all the created work sheets should be closed in the end when done...

  4. #4
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Re: Need to Split Data into sections and sheets

    This is what i got so far, its a work in progress....

    Sub Findexpand()
        Dim rFound As Range
        Dim FCell As String
        Dim sh As Worksheet
        Set sh = ThisWorkbook.Sheets("Test")
        Dim k As Long
        Dim tmpFile As String
        Dim MyData As String, strData() As String
        Dim entireline As String
        Dim filesize As Integer
        
        On Error Resume Next
        Set rFound = Cells.Find(What:="*", _
                        After:=Cells(Rows.Count, Columns.Count), _
                        LookAt:=xlPart, _
                        LookIn:=xlFormulas, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        
       On Error GoTo 0
        
         If rFound Is Nothing Then
            MsgBox "Done"
            
            End If
        Else
        
        FCell = rFound.Address(RowAbsolute:=False, ColumnAbsolute:=False, External:=False)
        k = sh.Range(FCell, sh.Range(FCell).End(xlDown).End(xlDown).End(xlUp)).Rows.Count
        ActiveSheet.Range(FCell).Select
        Selection.Resize(numRows + k, numColumns + 50).Select
        Selection.Cut
        ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
        ActiveSheet.Paste
        
        '~~> Change this where and how you want to save the file
        Const FlName = "C:\Users\Desktop\Chunk1.txt"
    
        '~~> Create a Temp File
        tmpFile = TempPath & Format(Now, "ddmmyyyyhhmmss") & ".txt"
    
        ActiveWorkbook.SaveAs Filename:=tmpFile _
        , FileFormat:=xlText, CreateBackup:=False
    
        '~~> Read the entire file in 1 Go!
        Open tmpFile For Binary As #1
        MyData = Space$(LOF(1))
        Get #1, , MyData
        Close #1
        strData() = Split(MyData, vbCrLf)
    
        '~~> Get a free file handle
        filesize = FreeFile()
    
        '~~> Open your file
        Open FlName For Output As #filesize
    
        For i = LBound(strData) To UBound(strData)
            entireline = Replace(strData(i), """", "")
            '~~> Export Text
            Print #filesize, entireline
        Next i
    
        Close #filesize
        Application.DisplayAlerts = False
    
        Worksheets(Worksheets.Count).Activate
        ActiveSheet.Delete
        Application.DisplayAlerts = True
    
        MsgBox "Done"
    '   Kill tmpFile
        
        
        End If
    
        
    End Sub
    Last edited by shelim481; 08-30-2018 at 10:57 AM.

  5. #5
    Registered User
    Join Date
    11-04-2015
    Location
    London, england
    MS-Off Ver
    2007
    Posts
    60

    Re: Need to Split Data into sections and sheets

    How do you loop the above code? Someone help....

+ 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. [SOLVED] VB Code to split data in 2 sheets
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2017, 09:21 PM
  2. [SOLVED] Split 1 worksheet into multiple sheets (sub-sections)
    By TheTallBloke in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-27-2017, 01:50 PM
  3. Need Macro code to split data split in 7 sheets based on variable rows in column A
    By Alija_21 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2015, 08:03 AM
  4. [SOLVED] vba to split column data into different sheets
    By vanitarathod in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2014, 02:42 AM
  5. Split data into different sheets
    By philiasfogg in forum Excel General
    Replies: 4
    Last Post: 09-14-2011, 11:32 AM
  6. Split Data to multiple Sheets
    By georgeanaprop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2010, 08:52 AM
  7. Split data into new sheets
    By bernard in forum Excel General
    Replies: 4
    Last Post: 01-04-2006, 12:50 PM

Tags for this Thread

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