LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help Please - VBA Macro- Copying rows to new file

Thank you so much!


MSP77079 wrote in message ...
What I would do is:

1) resort the original file by sales person (column G)
2) work down column G, each time the entry in column G changes, copy
that range of rows to a new file
3) sort the original file back the way it was in the beginning

Something like this:

Sub ExportBySalesPerson()

LastRow = Range("A1").End(xlDown).Row
Range("A1:G" & LastRow).Select
Selection.Sort Key1:=Range("G2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

SalesRep = Range("G2")
FirstRow = 2
For myRow = 2 To LastRow + 1
If Cells(myRow, "G") < SalesRep Then
Workbooks.Add Name:=SalesRep
ThisWorkbook.Activate
Rows("1:1").Copy
Destination:=Workbooks(SalesRep).Range("A1")
Range(Cells(FirstRow, "A"), Cells(myRow - 1, "G")).Copy _
Destination = Workbooks(SalesRep).Range("A2")
Application.CutCopyMode = False
Workbooks(SalesRep).Save
Workbooks(SalesRep).Close
End If
Next myRow

End Sub


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

 
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
Macro for copying a value to a variable no. of rows Ian Grega Excel Discussion (Misc queries) 6 April 15th 08 02:48 PM
Copying and Pasting Rows Macro tnederlof Excel Discussion (Misc queries) 1 February 2nd 07 05:23 PM
how i make a pgm in excel for copying all the rows to a new file . Copying after checking condition in Exce Excel Discussion (Misc queries) 1 April 3rd 05 06:43 PM
Copying rows from one file and pasting into a new file Tina Excel Programming 0 August 25th 03 04:34 AM
Copying rows from one file and pasting into a new file Stan Bauer Excel Programming 3 August 24th 03 10:41 PM


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