Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Using VB 6.0 to sort an Excel spreadsheet


Using VB 6.0 to sort an Excel spreadsheet

Reply
  #1 (permalink)  
Old 07-07-04, 09:53 AM
ChicagoIan ChicagoIan is offline
New Member
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Using VB 6.0 to sort an Excel spreadsheet

Ok, so I'm using VB 6.0 to create an Excel spreadsheet and once the data has been entered into the sheet, I'd like to sort it before I save the document. Here is the code I have so far when I sort...


Public Sub SortNames(oSheet As Object)

oSheet.Rows("9:32").Select
ActiveWindow.SmallScroll Down:=0
Selection.Sort Key1:=Range("A9"), Order1:=xlAscending, Key2:=Range("B9") _
, Order2:=xlAscending, Key3:=Range("C9"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


My problem is that once the code runs through the sort, it leaves the Excel.exe running in the background and when my program loops back in again to create another spreadsheet and hits the sorting function, it errors out. So right now only the first spreadsheet is being created, and after that it only errors out. Any help on getting the Excel.exe to close so I can create another spreadsheet?
Reply With Quote
  #2 (permalink)  
Old 07-12-06, 06:15 PM
lpmtv lpmtv is offline
New Member
 
Join Date: Jul 2006
Location: Moving to Seattle
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Using VB 6.0 to sort an Excel spreadsheet

I have saved data to an Excel spreadsheet a lot of times and have not
had the problem of Excel remaining running. This code seems to work
every time for me.

On Error Resume Next
MySheet.SaveAs strMyXLSInSpec
Set MySheet = Nothing
MyWorkbook.Close
Set MyWorkbook = Nothing
End

Does this work for you?

However, now I am trying to sort the spreadsheet and code that works fine as an Excel VBA macro doesn't work for me in VB.

I cannot get it to select (tried your code, too) and I cannot get it to select.
I get a message "Select method of object class fails."

A range seems to have a sort method.
I tried creating a datarange = datasheet.range(1,93) and then doing
datarange.sort but that does not work either.

Private Sub DoSortDataRowsByDate(datasheet As Worksheet)
Dim strcoords As String
Call DoGetColAlpha(intDataColCt, strColAlpha)
strcoords = "1:" & intDataRowCt
datasheet.Rows(strcoords).Select
Selection.Sort Key1:=Range("M1"), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers, _
DataOption2:=xlSortNormal
End Sub

Thanks for any tips you can give. Best, Lamont
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
click in image then export to excel angela ASP 4 09-02-10 05:55 AM
Creating an Excel page using VB 6.0 ChicagoIan Visual Basic 0 06-10-04 01:30 PM
VB 6.0 and VB .NET OMID SOFT Visual Basic 2 05-25-04 02:30 PM
XP Theme in VB 6.0 OMID SOFT Visual Basic 3 05-23-04 04:20 PM


All times are GMT -5. The time now is 09:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.