Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default creating unique new worksheets

I have a large list of data from a database, and need to turn that into
worksheets in a larger VBA macro (as there are many other things that I
need to do with it in the future).

It consists of a person's name, and then many pieces of data
afterwards. The data also comes out by week, so names are often
repeated. something like this:


NAME Var1 Var2 Var3 etc week number

Person1 data data data 10
Person2 data data data 10
Person3 data data data 10
Person1 data data data 9
Person2 data data data 9
Person3 data data data 9
Person1 data data data 8
etc...

I would like to be able to make a new worksheet for each person in the
overall list, and copy all of their data over to their new worksheet,
in an arbitrary cell number.

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default creating unique new worksheets

Sub test()
Const cPersonName = 1, cVar1 = 2, cVar2 = 3, cVar3 = 4, cWeek = 5
Dim wksS As Worksheet, wks As Worksheet, i As Long, j As Long,
lngLastRow As Long

Set wksS = Worksheets("Main Data")
lngLastRow = wksS.Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To lngLastRow
On Error Resume Next
Set wks = Worksheets(wksS.Cells(i, cPersonName).Value)
If Err.Number Then
Set wks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
wks.Name = wksS.Cells(i, cPersonName).Value
wks.Cells(1, cPersonName) = "Person Name"
wks.Cells(1, cVar1) = "Var1"
wks.Cells(1, cVar2) = "Var2"
wks.Cells(1, cVar3) = "Var3"
wks.Cells(1, cWeek) = "Week"
Err.Clear
End If
On Error GoTo 0

j = wks.Cells(Rows.Count, 1).End(xlUp).Row + 1
wks.Cells(j, cPersonName) = wksS.Cells(i, cPersonName)
wks.Cells(j, cVar1) = wksS.Cells(i, cVar1)
wks.Cells(j, cVar2) = wksS.Cells(i, cVar2)
wks.Cells(j, cVar3) = wksS.Cells(i, cVar2)
wks.Cells(j, cWeek) = wksS.Cells(i, cWeek)
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"stuph " wrote in message
...
I have a large list of data from a database, and need to turn that into
worksheets in a larger VBA macro (as there are many other things that I
need to do with it in the future).

It consists of a person's name, and then many pieces of data
afterwards. The data also comes out by week, so names are often
repeated. something like this:


NAME Var1 Var2 Var3 etc week number

Person1 data data data 10
Person2 data data data 10
Person3 data data data 10
Person1 data data data 9
Person2 data data data 9
Person3 data data data 9
Person1 data data data 8
etc...

I would like to be able to make a new worksheet for each person in the
overall list, and copy all of their data over to their new worksheet,
in an arbitrary cell number.

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default creating unique new worksheets

Wow! Thanks for such a quick and useful response... after editing thi
a bit, it will do exactly what i need.. thanks again..

Rob van Gelder wrote:
[b]Sub test()
Const cPersonName = 1, cVar1 = 2, cVar2 = 3, cVar3 = 4, cWeek = 5
Dim wksS As Worksheet, wks As Worksheet, i As Long, j As Long,
lngLastRow As Long

Set wksS = Worksheets("Main Data")
lngLastRow = wksS.Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To lngLastRow
On Error Resume Next
Set wks = Worksheets(wksS.Cells(i, cPersonName).Value)
If Err.Number Then
Set wks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
wks.Name = wksS.Cells(i, cPersonName).Value
wks.Cells(1, cPersonName) = "Person Name"
wks.Cells(1, cVar1) = "Var1"
wks.Cells(1, cVar2) = "Var2"
wks.Cells(1, cVar3) = "Var3"
wks.Cells(1, cWeek) = "Week"
Err.Clear
End If
On Error GoTo 0

j = wks.Cells(Rows.Count, 1).End(xlUp).Row + 1
wks.Cells(j, cPersonName) = wksS.Cells(i, cPersonName)
wks.Cells(j, cVar1) = wksS.Cells(i, cVar1)
wks.Cells(j, cVar2) = wksS.Cells(i, cVar2)
wks.Cells(j, cVar3) = wksS.Cells(i, cVar2)
wks.Cells(j, cWeek) = wksS.Cells(i, cWeek)
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/exce


--
Message posted from http://www.ExcelForum.com

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
date formating, creating unique calender Squeeker Excel Worksheet Functions 3 February 28th 10 11:35 PM
Creating a Unique List Ellen G Excel Discussion (Misc queries) 5 February 27th 10 10:37 AM
Creating a Unique Reference from 2 cells Christina Byrne Excel Discussion (Misc queries) 3 July 22nd 08 06:31 PM
Creating A Unique List of Values From A Table carl Excel Worksheet Functions 8 May 17th 07 11:39 AM
Any Way of Creating a 'Unique Key'? hustla7 New Users to Excel 6 August 19th 06 04:42 PM


All times are GMT +1. The time now is 07:29 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"