PC Review


Reply
Thread Tools Rate Thread

Create a new sheet for all Unique values

 
 
Snapdaddy
Guest
Posts: n/a
 
      12th Jan 2007
Hi,

I have some code that I got off of Ron DeBruin's site for Creating a
new sheet for all unique values. It works great but it puts the header
at the top of each new sheet. Is there a way to modify this code to
make it so it does not add a header at the top of each new sheet? I'm
just looking to put the raw data on each new sheet. Any help is
appreciated.

Sub Copy_With_AdvancedFilter_To_Worksheets()
Dim CalcMode As Long
Dim ws1 As Worksheet
Dim WSNew As Worksheet
Dim rng As Range
Dim cell As Range
Dim Lrow As Long

Set ws1 = Sheets("Sheet1") '<<< Change
'Tip : You can also use a Dynamic range name,
http://www.contextures.com/xlNames01.html#Dynamic
'or a fixed range like Range("A1:H1200")
Set rng = ws1.Range("A1").CurrentRegion '<<< Change

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = True
End With

With ws1
rng.Columns(1).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=.Range("IV1"), Unique:=True
'This example filter on the first column in the range (change
this if needed)
'You see that the last two columns of the worksheet are used to
make a Unique list
'and add the CriteriaRange.(you can't use this macro if you use
the columns)

Lrow = .Cells(Rows.Count, "IV").End(xlUp).Row
.Range("IU1").Value = .Range("IV1").Value

For Each cell In .Range("IV2:IV" & Lrow)
.Range("IU2").Value = cell.Value
Set WSNew = Sheets.Add
On Error Resume Next
WSNew.Name = cell.Value
If Err.Number > 0 Then
MsgBox "Change the name of : " & WSNew.Name & "
manually"
Err.Clear
End If
On Error GoTo 0
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("IU1:IU2"), _
CopyToRange:=WSNew.Range("A1"), _
Unique:=False
WSNew.Columns.AutoFit
Next
.Columns("IU:IV").Clear
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      12th Jan 2007
Hi Snapdaddy


For others the code is on this page
http://www.rondebruin.nl/copy5.htm

Add one line before the autofit line to delete the row

WSNew.Rows(1).Delete
WSNew.Columns.AutoFit


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Snapdaddy" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Hi,
>
> I have some code that I got off of Ron DeBruin's site for Creating a
> new sheet for all unique values. It works great but it puts the header
> at the top of each new sheet. Is there a way to modify this code to
> make it so it does not add a header at the top of each new sheet? I'm
> just looking to put the raw data on each new sheet. Any help is
> appreciated.
>
> Sub Copy_With_AdvancedFilter_To_Worksheets()
> Dim CalcMode As Long
> Dim ws1 As Worksheet
> Dim WSNew As Worksheet
> Dim rng As Range
> Dim cell As Range
> Dim Lrow As Long
>
> Set ws1 = Sheets("Sheet1") '<<< Change
> 'Tip : You can also use a Dynamic range name,
> http://www.contextures.com/xlNames01.html#Dynamic
> 'or a fixed range like Range("A1:H1200")
> Set rng = ws1.Range("A1").CurrentRegion '<<< Change
>
> With Application
> CalcMode = .Calculation
> .Calculation = xlCalculationManual
> .ScreenUpdating = True
> End With
>
> With ws1
> rng.Columns(1).AdvancedFilter _
> Action:=xlFilterCopy, _
> CopyToRange:=.Range("IV1"), Unique:=True
> 'This example filter on the first column in the range (change
> this if needed)
> 'You see that the last two columns of the worksheet are used to
> make a Unique list
> 'and add the CriteriaRange.(you can't use this macro if you use
> the columns)
>
> Lrow = .Cells(Rows.Count, "IV").End(xlUp).Row
> .Range("IU1").Value = .Range("IV1").Value
>
> For Each cell In .Range("IV2:IV" & Lrow)
> .Range("IU2").Value = cell.Value
> Set WSNew = Sheets.Add
> On Error Resume Next
> WSNew.Name = cell.Value
> If Err.Number > 0 Then
> MsgBox "Change the name of : " & WSNew.Name & "
> manually"
> Err.Clear
> End If
> On Error GoTo 0
> rng.AdvancedFilter Action:=xlFilterCopy, _
> CriteriaRange:=.Range("IU1:IU2"), _
> CopyToRange:=WSNew.Range("A1"), _
> Unique:=False
> WSNew.Columns.AutoFit
> Next
> .Columns("IU:IV").Clear
> End With
>
> With Application
> .ScreenUpdating = True
> .Calculation = CalcMode
> End With
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy unique values into listbox, then modify sheet from these values Matthew Dyer Microsoft Excel Programming 4 28th Sep 2009 04:11 PM
Create a new workbook for all Unique values and new work sheets tothat new workboks nazmul.bhuiyan@gmail.com Microsoft Excel Misc 0 1st Aug 2008 06:33 AM
Max length of text values in all fields, Unique values for all fields tcb Microsoft Access 1 8th Jun 2006 01:06 PM
create list of unique values from a column with repeated values? =?Utf-8?B?Q2hhZCBTY2hhYmVu?= Microsoft Excel Worksheet Functions 1 8th Jul 2005 10:25 PM
How do I search thr'o column and put unique values in differnt sheet and sum corresponding values in test test Microsoft Excel Programming 3 9th Sep 2003 08:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:48 AM.