Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Copying rows to different worksheets based on a cells value

I would like to write a macro to loop through each row of a worksheet titled
'Data' and copy each row into seperate worksheets, based on the value in
column A.

Col A Col B Col C etc
Test1 ... ......
Test2 .... ......
Test3 ...... ......
Test2 ...... .......

Row 1 would copy into worksheet 'Test1'
Row 2 would copy into worksheet 'Test2'
Row 3 would copy into worksheet 'Test3'
Row 4 would copy into worksheet 'Test1'

The worksheets to copy into are known and are already set up.

Any help on this problem would be very gratefully received.

Thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copying rows to different worksheets based on a cells value

Hi Dan,

Try something like:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim srcSH As Worksheet
Dim Rng As Range
Dim destRng As Range
Dim critRng As Range
Dim arrSheets As Variant
Dim arrKeyWords As Variant
Dim i As Long

Set WB = Workbooks("YourWorkbook.xls") '<<==== CHANGE
Set srcSH = WB.Sheets("Data")
Set Rng = srcSH.Range("A1").CurrentRegion

arrSheets = Array("Test1", "Test2", "Test3")
arrKeyWords = Array("TestA", "TestB", "TestC")

Set critRng = srcSH.Cells(1, Columns.Count). _
End(xlToLeft).Offset(0, 1).Resize(2, 1)
critRng(1).Value = Rng(1).Value

For i = LBound(arrSheets) To UBound(arrSheets)
critRng(2).Value = arrKeyWords(i)
Set SH = Sheets(arrSheets(i))
Set destRng = SH.Cells(Rows.Count, "A").End(xlUp)(2)
Rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=critRng, _
CopyToRange:=destRng, _
Unique:=False
Set destRng = Nothing
Next i

critRng.ClearContents

End Sub
'<<=============



---
Regards,
Norman



"DanSmoach" wrote in message
...
I would like to write a macro to loop through each row of a worksheet
titled
'Data' and copy each row into seperate worksheets, based on the value in
column A.

Col A Col B Col C etc
Test1 ... ......
Test2 .... ......
Test3 ...... ......
Test2 ...... .......

Row 1 would copy into worksheet 'Test1'
Row 2 would copy into worksheet 'Test2'
Row 3 would copy into worksheet 'Test3'
Row 4 would copy into worksheet 'Test1'

The worksheets to copy into are known and are already set up.

Any help on this problem would be very gratefully received.

Thanks





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copying rows to different worksheets based on a cells value

See
http://www.rondebruin.nl/copy5.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl


"DanSmoach" wrote in message ...
I would like to write a macro to loop through each row of a worksheet titled
'Data' and copy each row into seperate worksheets, based on the value in
column A.

Col A Col B Col C etc
Test1 ... ......
Test2 .... ......
Test3 ...... ......
Test2 ...... .......

Row 1 would copy into worksheet 'Test1'
Row 2 would copy into worksheet 'Test2'
Row 3 would copy into worksheet 'Test3'
Row 4 would copy into worksheet 'Test1'

The worksheets to copy into are known and are already set up.

Any help on this problem would be very gratefully received.

Thanks





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
Copying multiple rows to other worksheets (but amount of rows varies) - How? David Smithz Excel Discussion (Misc queries) 1 June 18th 06 04:31 PM
Copying worksheets into one workbook... based on content Petitboeuf Excel Discussion (Misc queries) 0 April 24th 06 01:21 PM
Is there a way to hide worksheets and/or rows/columns based on information enter into a particular cell of range of cells? Marc New Users to Excel 1 March 10th 06 05:10 PM
Copying whole rows based upon one criteria kirbster1973 Excel Discussion (Misc queries) 2 May 26th 05 10:00 PM
copying cells into different rows in different worksheets stephanie Excel Programming 2 November 29th 04 03:29 PM


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