LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Sorting Excel object?

Hi. I'm having trouble sorting an Excel spreadsheet that I create as an
object (see code below).

The code creates the spreadsheet and populates it from an outside data
source just fine.

However when I try to sort objExcel.Worksheets(1) (see the code), I get an
error message saying "Sort method of Range class failed". Thing is, when I
copy the sorting portion code into the VB editor window for the
objExcel.Worksheet, strip out "objExcel." then the sort works fine.

Any ideas on how I can sort the Excel object I've created? Thanks...

Public Sub PopulateWorksheetWithContacts()

Dim conn As Object
Dim contactSearch As Object
Dim i As Integer
Dim objExcel As New Excel.Application

Set conn = CreateObject("InterAction.Connection")

conn.Login

If conn.IsLoggedIn Then
Set contactSearch = conn.NewContactSearch
contactSearch.FolderId = "Firm Personnel"
contactSearch.Execute
Set contacts = contactSearch.Results
End If

objExcel.Workbooks.Add

If Not contacts Is Nothing Then
For i = 1 To contacts.Count
With objExcel.Worksheets(1)
.Cells(i, 1).Value = contacts(i).FirstName
.Cells(i, 2).Value = contacts(i).LastName
.Cells(i, 3).Value = contacts(i).Department
' .Cells(i, 4).Value = contacts(i).Phones(1).Phone
' .Cells(i, 5).Value = contacts(i).Eaddresses(1).Address
End With
Next i
Else
MsgBox "There has been a problem populating your Authors list"
End If

objExcel.Worksheets(1).Range("A1").Sort _
Key1:=Worksheets(1).Columns("A"), Order1:=xlAscending, _
Key2:=Worksheets(1).Columns("b"), Order2:=xlAscending, _
Key3:=Worksheets(1).Columns("c"), Order2:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom

End Sub

 
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
2 Label Options - Forms Object vs Control Box Object Awrex Excel Discussion (Misc queries) 3 July 17th 09 07:10 PM
returning pivottable object from a range object Grant Excel Programming 2 September 27th 04 02:22 AM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


All times are GMT +1. The time now is 12:19 AM.

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"