Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Create New sheet and copy appropriate data to new sheet

Hi all, I have two sheets in workbook. First Sheet names is "Data"
and the second Sheet names is "Template". In Sheet("Data") I have
below data.

A B C D…….col
Record1 LC1 1256 sus
Record1 LC1 1453 suv
Record1 LC1 1566 sut
Record2 LD1 1256 sus
Record2 LD1 1453 suv
Record2 LD1 1566 sut
Record3 LE1 1256 sus
Record3 LE1 1453 suv
Record3 LE1 1566 sut

I need macro on a button in Sheet("Data") which should copy Sheet
("Template") by looking at each unique value in column B of above data
and give the new copied Sheet the unique value name. For example
according to above data macro should copy Sheet("Template") three time
and name them LC1 , LD1 , LE1. While coping Sheet("Template"), macro
should also copy data of column A to D which is in same row of unique
value of column B into unique value sheet. For example

A B C D…….col
Record1 LC1 1256 sus
Record1 LC1 1453 suv
Record1 LC1 1566 sut
Above data should be copied in Sheet("LC1") in range A2

A B C D…….col
Record2 LD1 1256 sus
Record2 LD1 1453 suv
Record2 LD1 1566 sut
Above data should be copied in Sheet("LD1") in range A2

A B C D…….col
Record3 LE1 1256 sus
Record3 LE1 1453 suv
Record3 LE1 1566 sut
Above data should be copied in Sheet("LE1") in range A2

I hope I was able to explain my question. Please can any friend help
me.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Create New sheet and copy appropriate data to new sheet

place this in a standard module (ALT+F11 INSERT/MODULE)

Option Explicit
Dim rw As Long
Sub Maib()
Dim ws As Worksheet
Dim target As Range
With Worksheets("data")
.Cells.Sort Range("B1")
Set target = .Range("B1")
Do Until target = ""
Set ws = GetSheet(target.Value)
.Rows(target.Row).Copy
ws.Rows(rw).PasteSpecial xlAll
Set target = target.Offset(1)
Loop
End With
End Sub
Function GetSheet(sName As String) As Worksheet
On Error Resume Next
Set GetSheet = Worksheets(sName)
If Err.Number < 0 Then
Worksheets("template").Copy after:=Worksheets(Worksheets.Count)
Set GetSheet = Worksheets(Worksheets.Count)
GetSheet.Name = sName
rw = 0 'initialise
End If
rw = rw + 1
On Error GoTo 0
End Function


"K" wrote:

Hi all, I have two sheets in workbook. First Sheet names is "Data"
and the second Sheet names is "Template". In Sheet("Data") I have
below data.

A B C D€¦€¦.col
Record1 LC1 1256 sus
Record1 LC1 1453 suv
Record1 LC1 1566 sut
Record2 LD1 1256 sus
Record2 LD1 1453 suv
Record2 LD1 1566 sut
Record3 LE1 1256 sus
Record3 LE1 1453 suv
Record3 LE1 1566 sut

I need macro on a button in Sheet("Data") which should copy Sheet
("Template") by looking at each unique value in column B of above data
and give the new copied Sheet the unique value name. For example
according to above data macro should copy Sheet("Template") three time
and name them LC1 , LD1 , LE1. While coping Sheet("Template"), macro
should also copy data of column A to D which is in same row of unique
value of column B into unique value sheet. For example

A B C D€¦€¦.col
Record1 LC1 1256 sus
Record1 LC1 1453 suv
Record1 LC1 1566 sut
Above data should be copied in Sheet("LC1") in range A2

A B C D€¦€¦.col
Record2 LD1 1256 sus
Record2 LD1 1453 suv
Record2 LD1 1566 sut
Above data should be copied in Sheet("LD1") in range A2

A B C D€¦€¦.col
Record3 LE1 1256 sus
Record3 LE1 1453 suv
Record3 LE1 1566 sut
Above data should be copied in Sheet("LE1") in range A2

I hope I was able to explain my question. Please can any friend help
me.

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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
1 Create a macro to Copy & paste certain data to another sheet Lin1981 Excel Discussion (Misc queries) 1 November 6th 08 11:56 PM
Create new sheets based off Data sheet, and template sheet Midget Excel Programming 2 May 1st 07 09:55 PM
create a formula in one sheet that would read data from separate sheet automatically QD Excel Discussion (Misc queries) 0 December 8th 06 04:17 AM
How to create a Macro to Copy Information in one sheet to another sheet. poppy Excel Programming 3 July 28th 04 07:26 AM


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

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

About Us

"It's about Microsoft Excel"