#1   Report Post  
Posted to microsoft.public.excel.programming
Aze Aze is offline
external usenet poster
 
Posts: 1
Default column

hi,
wrote code in VB.NET to sort selected range of data in excel. Data is sorted
but the problem is sorted column values remove i.e in the code below i sort
"rng.Columns(1)" data sorted perfectly, but all the column become empty. i
dont whats the problem in coding or do i miss something?

Dim EXL As New Excel.Application()
Dim WSheet As New Excel.Worksheet()
WSheet = EXL.Workbooks.Open("c:\test.xls").Worksheets.Item( 1)

Dim R As Excel.Range
R = WSheet.UsedRange
Dim R1 As Excel.Range
R1 = WSheet.UsedRange
Dim TotRowsCols() As String
Dim TotNumRow() As String
Dim WSSize As String
WSSize = R1.Cells.Address()
TotRowsCols = WSSize.Split(":")
TotNumRow = TotRowsCols(1).Split("$")

Dim rng As Excel.Range = EXL.Range("a2:AK" & TotNumRow(2))
EXL.Selection.sort( _
Key1:=rng.Columns(1), Order1:=Excel.XlSortOrder.xlAscending, _
Orientation:=Excel.XlSortOrientation.xlSortColumns , _
Header:=Excel.XlYesNoGuess.xlGuess, _
Orientation:=Excel.XlSortOrientation.xlSortColumns )
Try
'Saving .xls file with Test.xls name
WSheet.SaveAs("C:\TEST1.XLS")
Catch
End Try
EXL.Workbooks.Close()
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
divide column(x) by column(y) to give column(x/y) in excel? James New Users to Excel 2 April 24th 23 11:46 AM
Calculating column A * column B = Results in another column jhun Excel Worksheet Functions 2 March 30th 10 05:13 AM
Referencing date column A & time column B to get info from column TVGuy29 Excel Discussion (Misc queries) 1 January 24th 08 09:50 PM
Return text in Column A if Column B and Column K match jeannie v Excel Worksheet Functions 4 December 13th 07 07:36 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM


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