Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
wham
 
Posts: n/a
Default Using a cell reference to copy rows to a new worksheet


Hi there - was a bit tongue tied with the thread title so I hope it
adequately describes my problem.

I've been tasked with redoing a revenue report at work, and in my head
I've conjured up what could potentially be a huge time saving way of
doing things in the future, although have searched help files and
looked around online and can't find the formula/macro (if it exists) to
enable me to do this.


The problem is this:

Sheet 1 of the workbook is a large input sheet. Every row contained in
that sheet will, in column A, be titled 'red', 'yellow' or 'green'.
Columns B onwards contain other data which (at the moment) is
irrelevant to the problem.

Now what I want excel to do after I've put the raw data into the input
sheet (sheet 1), is to read the text in column A for each row, then
automatically copy ALL data in that row over to the next empty row on
another worksheet.

ie Sheet 2 will have all rows that have 'Red' in column A on the input
sheet, Sheet 3 will have all those titled 'Yellow' and Sheet 4 will
have all those titled 'Red'.

Is this something that is possible?

I know I can use a filter on the input sheet to just show the data I
want, but each colour coded row will contain different data to another,
and if there is a formula/macro setup i can use to do the above, then I
can set the subsequent worksheets up to hide the superflous columns
from the input sheet.

Hope that makes sense, and hope one of you guys is able to help.

Thanks

Wayne


--
wham
------------------------------------------------------------------------
wham's Profile: http://www.excelforum.com/member.php...o&userid=35395
View this thread: http://www.excelforum.com/showthread...hreadid=551680

  #2   Report Post  
Posted to microsoft.public.excel.misc
Max
 
Posts: n/a
Default Using a cell reference to copy rows to a new worksheet

Here's a play which automates it using non-array formulas ..

A sample construct is available at:
http://www.savefile.com/files/9260836
AutoCopy_Data_To_Resp_Sheet_Non_Array_Approach.xls

In sheet: WS1 (the "master")

Assume data in cols A to D, data in row2 down,
with the key col = col A (colours)

List the colours across in K1:M1, viz.: red, yellow, green

Put in K2: =IF($A2=K$1,ROW(),"")
Copy across to M2, fill down to say, M20
to cover the max expected extent of data

Click Insert Name Define
Put under "Names in workbook:": WSN
Put in the "Refers to:" box:
=MID(CELL("Filename",INDIRECT("A1")),FIND("]",CELL("Filename",INDIRECT("A1")
))+1,32)
Click OK

The above defines WSN as a name we can use to refer to the sheetname in
formulas. It will auto-extract the sheetname implicitly. Technique came from
a post by Harlan.

In a new sheet named: Red
With the same col headers pasted into A1:D1

Put in A2:
=IF(ISERROR(SMALL(OFFSET(WS1!$J:$J,,MATCH(WSN,WS1! $K$1:$M$1,0)),ROWS($A$1:A1))),"",INDEX(WS1!A:A,MAT CH(SMALL(OFFSET(WS1!$J:$J,,MATCH(WSN,WS1!$K$1:$M$1 ,0)),ROWS($A$1:A1)),OFFSET(WS1!$J:$J,,MATCH(WSN,WS 1!$K$1:$M$1,0)),0)))

Copy A2 across to D2, fill down to say, D10
[copy down by the smallest possible range sufficient to cover the max
expected extent for any category. Here, I've assumed that 9 rows (rows 2 to
10) is sufficient]

Cols A to D will return only the lines for colour: Red from "WS1",
with all lines neatly bunched at the top

Now, just make a copy of the sheet: Red, rename it as: Green, and we'd get
the results for the colour: Green. Repeat the copy rename sheet process to
get the rest of the colour sheets (a one-time job). Adapt to suit ..
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"wham" wrote:
Hi there - was a bit tongue tied with the thread title so I hope it
adequately describes my problem.

I've been tasked with redoing a revenue report at work, and in my head
I've conjured up what could potentially be a huge time saving way of
doing things in the future, although have searched help files and
looked around online and can't find the formula/macro (if it exists) to
enable me to do this.


The problem is this:

Sheet 1 of the workbook is a large input sheet. Every row contained in
that sheet will, in column A, be titled 'red', 'yellow' or 'green'.
Columns B onwards contain other data which (at the moment) is
irrelevant to the problem.

Now what I want excel to do after I've put the raw data into the input
sheet (sheet 1), is to read the text in column A for each row, then
automatically copy ALL data in that row over to the next empty row on
another worksheet.

ie Sheet 2 will have all rows that have 'Red' in column A on the input
sheet, Sheet 3 will have all those titled 'Yellow' and Sheet 4 will
have all those titled 'Red'.

Is this something that is possible?

I know I can use a filter on the input sheet to just show the data I
want, but each colour coded row will contain different data to another,
and if there is a formula/macro setup i can use to do the above, then I
can set the subsequent worksheets up to hide the superflous columns
from the input sheet.

Hope that makes sense, and hope one of you guys is able to help.

Thanks

Wayne


--
wham
------------------------------------------------------------------------
wham's Profile: http://www.excelforum.com/member.php...o&userid=35395
View this thread: http://www.excelforum.com/showthread...hreadid=551680


  #3   Report Post  
Posted to microsoft.public.excel.misc
Leith Ross
 
Posts: n/a
Default Using a cell reference to copy rows to a new worksheet


Hello Wayne,

Here is a VBA macro version. To use it , add a VBA Module to your
project code. You can then run it by selecting it the Macro Dialog Box.
To display the available macros in Excel press ALT + F8.

Code:
--------------------

Public Sub SplitAndCopyRows()

Dim Cell As Range
Dim I As Long
Dim LastRow As Long
Dim NextRow(3) As Long
Dim MainWks As Worksheet
Dim Wks As Worksheet

Set MainWks = Worksheets("Sheet1")
LastRow = MainWks.Range("A" & MainWks.Rows.Count).Row

With Worksheets("Sheet2")
NextRow(1) = .Range("A" & .Rows.Count).End(xlUp).Row
End With

With Worksheets("Sheet3")
NextRow(2) = .Range("A" & .Rows.Count).End(xlUp).Row
End With

With Worksheets("Sheet4")
NextRow(3) = .Range("A" & .Rows.Count).End(xlUp).Row
End With

For Each Cell In MainWks.Range("A1:A" & LastRow)
Select Case LCase(Cell.Value)
Case Is = "red"
Set Wks = Worksheets("Sheet2")
I = 1
GoSub CopyToNextRow
Case Is = "yellow"
Set Wks = Worksheets("Sheet3")
I = 2
GoSub CopyToNextRow
Case Is = "green"
Set Wks = Worksheets("Sheet4")
I = 3
GoSub CopyToNextRow
End Select
Next Cell

Exit Sub

CopyToNextRow:
If NextRow(I) < 1 Or (NextRow(I) = 1 And Wks.Cells(1, 1).Value < "") Then
NextRow(I) = NextRow(I) + 1
End If
MainWks.Range(Cell.Address).EntireRow.Copy Destination:=Wks.Range("A" & NextRow(I)).EntireRow
Return

End Sub
--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=551680

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
Adding a row to worksheet does not update cell references in another. blausen Excel Worksheet Functions 5 February 25th 06 09:14 PM
How do I copy a date in a worksheet cell to another worksheet? JennLee Excel Worksheet Functions 3 February 17th 06 05:38 PM
how do i copy rows to a new worksheet by a cell value Nibbs New Users to Excel 1 February 8th 06 04:03 PM
How to use a cell value to reference a worksheet name S2 Excel Worksheet Functions 2 October 10th 05 03:02 PM
Cell Reference Math Ralph Howarth Excel Worksheet Functions 0 January 26th 05 06:27 PM


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