Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

sort and copy selection to other worksheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Helmut - 13 Mar 2008 15:13 GMT
I have the following: -BUT it doesn't sort Column R

'   determine total range for sorting

  Dim lr As Long, lc As Long '(in declarations)

lc = ActiveSheet.Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
lr = ActiveSheet.Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

   Cells.Select
   ActiveSheet.Sort.SortFields.Clear
   ActiveSheet.Sort.SortFields.Add _
  Key:=Range(Cells(1, 1), Cells(lr, 1)) _
  , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveSheet.Sort
       .SetRange Range(Cells(1, 1), Cells(lr, lc))
       .Header = xlGuess
       .MatchCase = False
       .Orientation = xlTopToBottom
       .SortMethod = xlPinYin
       .Apply
   End With

After this sorts Column R, I then need to copy values of Fields C,D,E for
the rows where value in R = #N/A to another WorkSheet.
Can you help?
David Ritchie - Oz - 18 Mar 2008 13:31 GMT
Hi Helmut

Based on what you supplied, this code might do the job:
Assumptions :
- sheet1 contains a number of columns A-R
- sheet2 is the destination sheet
- All data starts at row 1, column A

<-- snip start -->
'I have the following: -BUT it doesn't sort Column R

'   determine total range for sorting

  Dim lr As Long, lc As Long '(in declarations)
Sub testme()

lc = sheet1.Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
lr = sheet1.Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

   Sheet1.Range("A1").Sort _
     Key1:=Range(Cells(1, lc), Cells(lr, lc)), _
     Order1:=xlAscending, _
     DataOption1:=xlSortNormal, _
     Header:=xlGuess
     
     Dim eRng As Range
     
     Set eRng = Range("A1").SpecialCells(xlCellTypeConstants, xlErrors)
     Range(Cells(eRng.Row, 3), Cells(eRng.Row + eRng.Rows.Count - 1,
5)).Select
     Selection.Copy Destination:=Worksheets("Sheet2").Range("E5")

End Sub
'After this sorts Column R, I then need to copy values of Fields C,D,E for
'the rows where value in R = #N/A to another WorkSheet.
'Can you help?

<--  snip end -->

Cheers David

> I have the following: -BUT it doesn't sort Column R
>
[quoted text clipped - 22 lines]
> the rows where value in R = #N/A to another WorkSheet.
> Can you help?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.