Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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 12:49 PM.

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"