Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / May 2008

Tip: Looking for answers? Try searching our database.

Auto generate sheets by different values of a cell.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dawn - 15 May 2008 05:06 GMT
I have a sheet in excel ,with the following fields
Name, gender…,city.
I want to use excel to auto generate sheets according to the value of the
field city.
For example :
If the city only has two values :LA, NY
Excel will generate two new sheets ,”LA” with the all the records in
original sheet but the city value=LA; ”NY” with the all the records in
original sheet but the city value=NY;
How can I realize it.
Many thanks.
Joel - 15 May 2008 10:46 GMT
With Sheets("sheet1")
  .Columns("F").AdvancedFilter _
     Unique:=True, Action:=xlFilterInPlace
  Set UniqueCities = .Columns("F").SpecialCells( _
     Type:=xlCellTypeVisible, _
     Value:=xlTextValues)

  For Each city In UniqueCities
     If city <> "" Then
        .Columns("F").AutoFilter _
           field:=1, _
           Criteria1:=city
     
        Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
        newsht.Name = city
        .Cells.SpecialCells(Type:=xlCellTypeVisible).EntireRow.Copy _
           Destination:=newsht.Cells
        If .FilterMode = True Then
           .ShowAllData
        End If
     End If
  Next city
End With

> I have a sheet in excel ,with the following fields
> Name, gender…,city.
[quoted text clipped - 7 lines]
> How can I realize it.
> Many thanks.
Dawn - 16 May 2008 08:58 GMT
Dear Joel,
I am a basic learner of excel.
Is the above VBA or Marco? Can you take some trouble as to tell me how do I
put these sentences in excel in details.
I am absolutely don’t know where to start. Pls help me, thanks.
Dawn
Joel - 16 May 2008 09:46 GMT
VBA is the visual basic Application that runs macros.  You can have either
subroutines (Sub) or Functions, both are reffered to as macros.  This code is
a subroutine.

1) Go to the VBA envirnoment Press Alt F11.
2) VBA Menu - Insert - Module
3) Copy macro from the word SUB to END SUB and paste into module sheet
4) You can run the macro 2 different ways.
  a) from VBA press F5 (or menu Run - Run)
  b) From Worksheet Tools - Macro - Macro - MakeSheets

You didn't specify the worksheet name or the column  letter where the citiy
names are located.  You may need to change these two lines

  1) FiltCol = "F" which is the column where the cities are located
  2) With Sheets("sheet1") which is the sheet name where you original data
is located.

Sub MakeSheets()

FiltCol = "F"    '<= change if necessary

With Sheets("sheet1")    '<= change if necessary

  .Columns(FiltCol).AdvancedFilter _
     Unique:=True, Action:=xlFilterInPlace
  Set UniqueCities = .Columns("F").SpecialCells( _
     Type:=xlCellTypeVisible, _
     Value:=xlTextValues)

  For Each city In UniqueCities
     If city <> "" Then
        .Columns(FiltCol).AutoFilter _
           field:=1, _
           Criteria1:=city
     
        Set newsht = Sheets.Add(after:=Sheets(Sheets.Count))
        newsht.Name = city
        .Cells.SpecialCells(Type:=xlCellTypeVisible).EntireRow.Copy _
           Destination:=newsht.Cells
        If .FilterMode = True Then
           .ShowAllData
        End If
     End If
  Next city
End With
End Sub

> Dear Joel,
> I am a basic learner of excel.
> Is the above VBA or Marco? Can you take some trouble as to tell me how do I
> put these sentences in excel in details.
> I am absolutely don’t know where to start. Pls help me, thanks.
> Dawn
Dawn - 19 May 2008 04:30 GMT
Hi Joel, helpful indeed!
Many thanks for the detailed instruction.
For further problems may encount with, will consult with you later.

> VBA is the visual basic Application that runs macros.  You can have either
> subroutines (Sub) or Functions, both are reffered to as macros.  This code is
[quoted text clipped - 50 lines]
> > I am absolutely don’t know where to start. Pls help me, thanks.
> > Dawn
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.