Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
cougarman
 
Posts: n/a
Default Add worksheets based on cell value

I have a single worksheet workbook that contains client names in column
A, and associated data in the other columns. There are multiple
records (rows) for each client. Is it possible to use a macro or VB
script to scan column A, and move all records associated with each
client to a new worksheet (and change the worksheet name to the
client's name)?

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Add worksheets based on cell value

Debra Dalgleish and Ron de Bruin have samples that you may like. Ron's addin
may be sufficient right out of the box.

Debra's site:
http://www.contextures.com/excelfiles.html

Create New Sheets from Filtered List -- uses an Advanced Filter to create
separate sheet of orders for each sales rep visible in a filtered list; macro
automates the filter. AdvFilterRepFiltered.xls 35 kb

or

Update Sheets from Master -- uses an Advanced Filter to send data from
Master sheet to individual worksheets -- replaces old data with current.
AdvFilterCity.xls 55 kb

And Ron de Bruin's easyfilter.
http://www.rondebruin.nl/easyfilter.htm

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

cougarman wrote:

I have a single worksheet workbook that contains client names in column
A, and associated data in the other columns. There are multiple
records (rows) for each client. Is it possible to use a macro or VB
script to scan column A, and move all records associated with each
client to a new worksheet (and change the worksheet name to the
client's name)?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
cougarman
 
Posts: n/a
Default Add worksheets based on cell value

Thank you Dave! I will be reviewing these links as time permits
today. I appreciate your feedback.

  #4   Report Post  
Posted to microsoft.public.excel.misc
cougarman
 
Posts: n/a
Default Add worksheets based on cell value

Dave -

I copied Debra Dalgleish's code, and experimented with it. It appears
that only the first 7 columns of data get copied to the new worksheets.
If I run the code against 9 columns, it doesn't move the last 2
columns. Any idea why?

  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Add worksheets based on cell value

Depending on what code you used...

Debra has a line like this that defines the range to be copied:

Set rng = Range("Database")

Database is a range that's exactly 7 columns wide.

You could use Insert|name|define to change that range.

But you have to be careful. Debra's code uses column J and L for storing the
unique values in the list. You may want to move them way over to the far right
(IU & IV???).

I looked at:
Create New Sheets from Filtered List
from Deb's site.

cougarman wrote:

Dave -

I copied Debra Dalgleish's code, and experimented with it. It appears
that only the first 7 columns of data get copied to the new worksheets.
If I run the code against 9 columns, it doesn't move the last 2
columns. Any idea why?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
cougarman
 
Posts: n/a
Default Add worksheets based on cell value

Thanks Dave! It's working pretty well for me. Baby steps...baby
steps....
Now wondering how to create new workbook(s) for each client value. ???

  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Add worksheets based on cell value

You may want to look at Ron de Bruin's code:

Ron de Bruin wrote:

Hi

On this page there is a example for workbooks also
http://www.rondebruin.nl/copy5.htm


(Ron posted this very recently to a very similar question.)

or you could try this change to Debra's code:

Option Explicit
Sub ExtractReps()

Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Range
Set ws1 = Sheets("Sheet1")
Set rng = Range("Database")

'extract a list of Sales Reps
ws1.Columns("C:C").Copy _
Destination:=Range("L1")

ws1.Columns("L:L").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True

r = ws1.Cells(ws1.Rows.Count, "J").End(xlUp).Row

'set up Criteria Area
ws1.Range("L1").Value = ws1.Range("C1").Value

For Each c In ws1.Range("J2:J" & r)
'add the rep name to the criteria area
ws1.Range("L2").Value = c.Value
'add new sheet (if required)
'and run advanced filter

Set wsNew = Workbooks.Add(1).Worksheets(1)
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=ws1.Range("L1:L2"), _
CopyToRange:=wsNew.Range("A1"), _
Unique:=False
Next
ws1.Parent.Activate
ws1.Select
ws1.Columns("J:L").Delete
End Sub


cougarman wrote:

Thanks Dave! It's working pretty well for me. Baby steps...baby
steps....
Now wondering how to create new workbook(s) for each client value. ???


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Add worksheets based on cell value

I had some unqualified ranges:

Option Explicit
Sub ExtractReps()

Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Range
Set ws1 = Sheets("Sheet1")
Set rng = Range("Database")

'extract a list of Sales Reps
ws1.Columns("C:C").Copy _
Destination:=ws1.Range("L1")

ws1.Columns("L:L").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=ws1.Range("J1"), Unique:=True

r = ws1.Cells(ws1.Rows.Count, "J").End(xlUp).Row

'set up Criteria Area
ws1.Range("L1").Value = ws1.Range("C1").Value

For Each c In ws1.Range("J2:J" & r)
'add the rep name to the criteria area
ws1.Range("L2").Value = c.Value
Set wsNew = Workbooks.Add(1).Worksheets(1)
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=ws1.Range("L1:L2"), _
CopyToRange:=wsNew.Range("A1"), _
Unique:=False
Next
ws1.Parent.Activate
ws1.Select
ws1.Columns("J:L").Delete
End Sub


cougarman wrote:

Thanks Dave! It's working pretty well for me. Baby steps...baby
steps....
Now wondering how to create new workbook(s) for each client value. ???


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formatiing based on another cell Number_8 Excel Discussion (Misc queries) 3 March 13th 06 12:35 PM
Locate a cell, based on a criteria, then use the 'Cell' command... cdavidson Excel Discussion (Misc queries) 1 November 17th 05 06:30 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Linking a cell to another workbook cell based on a variable name Brian Excel Discussion (Misc queries) 6 June 1st 05 11:54 PM
Copy cell format to cell on another worksht and update automatical kevinm Excel Worksheet Functions 21 May 19th 05 11:07 AM


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"