+ Reply to Thread
Results 1 to 19 of 19

Splitting names in to sheets in alphabetical order

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Splitting names in to sheets in alphabetical order

    Dear friends

    Hai i have attached one excel file there ,a macro will split all the names to different sheets by creating sheets with names as alphabets..
    I want certain things to be done over here

    1 Only first column of names are populated in other sheets but what ever columns available in the name sheet ,that should also come in to the sheets
    2 the names are coming in the first column of all the sheets,but serial no should be generated in all the sheets
    3 only if i dont add serial no in the name sheet it works ,otherwise if i add sl no in the name sheet,sheets are getting created with names as 1 2 3 ,etc
    4 after creating different sheets ,individual excel books should be formed with names as sheets names and these individual excel files should be saved in the folder d:/siva
    5 presently it is not auto fitting ,all columns should be autofit

    Please kindly help to modify this macro ...
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Dear friends can any body help me with my macro
    even if u can help me with any one requiremnt it is well and good ....

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Splitting names in to sheets in alphabetical order

    Hello catchnanan,

    I have added a button to the "Names" sheet. It will run the macro below which creates a new workbook for each name. The serial number appears in "A1" and row 2 will display the name and information associated with it.

    Sub CreateWorkbooks()
    
        Dim Data As Variant
        Dim Filepath As String
        Dim Rng As Range
        Dim Row As Long
        Dim Wkb As Workbook
        Dim Wks As Worksheet
        
            Filepath = "C:\Users\Owner\Documents\Excel Forum\catchnanan"
            Set Rng = Worksheets("Names").Range("B2").CurrentRegion
            
                For Row = 1 To Rng.Rows.Count
                   Data = Application.Index(Rng.Rows(Row), 1, 0)
                   Set Wkb = Workbooks.Add(xlWBATWorksheet)
                   Wkb.Sheets(1).Range("A1") = Row
                   Wkb.Sheets(1).Range("A2").Resize(1, UBound(Data, 2)).Value = Data
                   Wkb.SaveAs Filepath & "\" & Data(Row, 1) & ".xlsx"
                   Wkb.Close
                Next Row
        
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    thank u very much for your response....but i am sorry ...did u run my macro? then u will get exactly what i need
    here names say MARTIN ,JOSEPH,EDWARD ,ETC are in the name sheet ...my macro will create sheets with names "A","B","C"......etc
    and these names starting with A will settle in to the sheet "A" and so on ....
    what i importantly need is the information which are associated also should go and serial no should be created in all the sheets

    Can u see my macro and correct it accordingly ,,,

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,760

    Re: Splitting names in to sheets in alphabetical order

    Perhaps something like this?

    To test run macro "SqrSplit"


    Alf
    Attached Files Attached Files

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

    Re: Splitting names in to sheets in alphabetical order

    Change to
    Sub test()
        Dim rng As Range, a, i As Long, temp As String
        Application.ScreenUpdating = False
        Set rng = Sheets("names").Range("b2").CurrentRegion
        a = rng.Columns(1).Value
        With CreateObject("System.Collections.SortedList")
            For i = 1 To UBound(a, 1)
                temp = UCase$(Left$(a(i, 1), 1))
                If temp <> "" Then
                    If Not .Contains(temp) Then
                        Set .Item(temp) = rng.Rows(i)
                    Else
                        Set .Item(temp) = Union(.Item(temp), rng.Rows(i))
                    End If
                End If
            Next
            For i = .Count - 1 To 0 Step -1
                If Not IsSheetExists(.GetKey(i)) Then
                    Sheets.Add().Name = .GetKey(i)
                End If
                Sheets(.GetKey(i)).Move after:=rng.Parent
                .GetByIndex(i).Copy Sheets(.GetKey(i)).Cells(1)
            Next
        End With
        Application.ScreenUpdating = True
    End Sub
    
    Function IsSheetExists(ByVal txt As String) As Boolean
        On Error Resume Next
        IsSheetExists = Len(Sheets(txt).Name)
        On Error GoTo 0
    End Function
    Attached Files Attached Files
    Last edited by jindon; 12-25-2013 at 08:53 PM.

  7. #7
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Hai alf ,jindon ,leith ross ,thank u very much for all your assistance...
    I am very happy that one major problem of bringing other columns in to the sheets is solved..
    As i told earlier ,two drawbacks (still exists) of these macro are
    1) after shooting of names to other sheets,the names are displayed in all the sheets without serial numbers 1,2,3,ets
    2) In the sheet "names" the macro does not have the control over which column it is considering to break the names,
    by default ,it takes the first used column and it splits according to what is available in the first used column (for example if serial no is present in the first column,it splits these serial numbers and generates sheets like 1,2,3,4 etc)which is wrong ...It will be very fine it should always take from second column and also mainly cell B2 because it should leave space for title ,otherwise title name also go to some sheets...
    Last edited by catchnanan; 12-26-2013 at 04:30 PM.

  8. #8
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Hai alf ,jindon ,leith ross ,thank u very much for all your assistance...
    I am very happy that one major problem of bringing other columns in to the sheets is solved..
    As i told earlier ,two drawbacks (still exists) of these macro are
    1) after shooting of names to other sheets,the names are displayed in all the sheets without serial numbers 1,2,3,ets
    2) In the sheet "names" the macro does not have the control over which column it is considering to break the names,
    by default ,it takes the first used column and it splits according to what is available in the first used column (for example if serial no is present in the first column,it splits these serial numbers and generates sheets like 1,2,3,4 etc)which is wrong ...It will be very fine it should always take from second column and also mainly cell B2 because it should leave space for title ,otherwise title name also go to some sheets...
    So only if the first column is entirely empty ,it takes the names in the second column so i am unable to add serial numbers or any other things in the first column...
    Last edited by catchnanan; 12-26-2013 at 12:48 PM. Reason: More details

  9. #9
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Hai can any body pay attention...

  10. #10
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    hai can u plz help with some more as i asked yesterday...

  11. #11
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    hai can u plz help with some more as i asked yesterday...

  12. #12
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Can any body help me by coming up with solutions for the last two simple drawbacks of my interesting but very useful macro..

  13. #13
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Can any body help me by coming up with solutions for the last two simple drawbacks of my interesting but very useful macro..

  14. #14
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Splitting names in to sheets in alphabetical order

    modified test-macro
    Sub test()
      Dim rng As Range, a, i As Long, temp As String
      Application.ScreenUpdating = False
    
      Set rng = Sheets("names").Range("b2").CurrentRegion
      With rng
        a = .Offset(2 - .Row, 2 - .Column).Resize(, 1).Value   'Always start with B2
      End With
    
      With CreateObject("System.Collections.SortedList")
        For i = 1 To UBound(a, 1)
          temp = UCase$(Left$(a(i, 1), 1))
          If temp <> "" Then
            If Not .Contains(temp) Then
              Set .Item(temp) = rng.Rows(i)
            Else
              Set .Item(temp) = Union(.Item(temp), rng.Rows(i))
            End If
          End If
        Next
        
        For i = .Count - 1 To 0 Step -1
          If Not IsSheetExists(.GetKey(i)) Then
            Sheets.Add().Name = .GetKey(i)
          End If
          Sheets(.GetKey(i)).Move after:=rng.Parent
          .GetByIndex(i).Copy Sheets(.GetKey(i)).Cells(2, 2)
          With Sheets(.GetKey(i)).UsedRange
            With .Offset(, 1 - .Column).Resize(, 1)
              .FormulaR1C1 = "=row()-1"
              .Value = .Value
            End With
            .Parent.Rows(1).EntireColumn.AutoFit
          End With
        Next
      End With
      
      Application.ScreenUpdating = True
    End Sub

  15. #15
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Hai dear thank u very much ...It is very nice ..and 100 % perfect and I am really happy about it.I really thanks all the guys who helped me.. Last but least can this macro be further taken to the level where it ask us the column no when we run the macro,and if we give column no 4 it should break and create sheets based on the names in column 4 and so on
    Last edited by catchnanan; 12-28-2013 at 04:03 PM.

  16. #16
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Splitting names in to sheets in alphabetical order

    an new macro "Question" and the first lines of the changed macro "test"
    Sub Question()
    
      Dim MyCell   As Range
      If ActiveSheet.Name <> Sheets("names").Name Then GoTo fout
      On Error GoTo fout
      Set MyCell = Application.InputBox("Select your startcell", UCase("Choose the cell with your first name"), Type:=8)
      Test MyCell
      Exit Sub
    fout:
      MsgBox "macro stopped because of an error" & vbLf & "or you're in the wrong tab or didn't select a cell", vbExclamation
    
    End Sub
    
    
    Sub Test(ByRef rFirstName As Range)
      Dim rng As Range, a, i As Long, temp As String
      Application.ScreenUpdating = False
    
      Set rng = rFirstName.CurrentRegion
      With rng
        a = .Offset(rFirstName.Row - .Row, rFirstName.Column - .Column).Resize(, 1).Value   'Always start with B2
      End With
    
      With CreateObject("System.Collections.SortedList")
      ...

  17. #17
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    Hai dear thank u very much ...It is very nice ..and 100 % perfect and I am really happy about it.I really thanks all the guys who helped me.. Last but least can this macro be further taken to the level where it ask us the column no when we run the macro,and if we give column no 4 it should break and create sheets based on the names in column 4 and so on

  18. #18
    Forum Contributor
    Join Date
    07-07-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Splitting names in to sheets in alphabetical order

    thank u soooo much .It is amazing

    I am sorry to disturb u friend ,is there any way to create message box which asks us "Do u wnt to clr the old data?" depending upon yes or no ,it should either clear the existing data in all the sheets and replaces with the new one when the macro is run otherwise when the macro is run the date should be added to the existing data in the sheets.
    Last edited by catchnanan; 12-29-2013 at 10:06 AM.

  19. #19
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Splitting names in to sheets in alphabetical order

    see attachment
    Attached Files Attached Files

+ 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] INDEX names in alphabetical order. Horizontally.
    By JasonNeedsHelp in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-20-2013, 11:43 AM
  2. [SOLVED] How to sort sheets into alphabetical order?
    By senorkevin in forum Excel General
    Replies: 5
    Last Post: 11-13-2012, 03:13 PM
  3. sort last names by in alphabetical order
    By Jackie in forum Excel General
    Replies: 1
    Last Post: 05-24-2006, 03:50 PM
  4. [SOLVED] How do I arrange sheets in alphabetical order?
    By Supreme Grace in forum Excel General
    Replies: 2
    Last Post: 03-16-2005, 01:06 PM
  5. [SOLVED] How do I arrange sheets in alphabetical order?
    By gracebakky in forum Excel General
    Replies: 2
    Last Post: 03-16-2005, 07:06 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