Solved

Secondary Sort

Posted on 2004-09-10
15
363 Views
Last Modified: 2013-12-18
Does anyone know what the code would be to do a secondary sort when exporting to Excel. I want it to first sort by column A and then by column B.

      Set xlSheet = xlApp.Workbooks(1).Worksheets("Sheet1")
      Set range1 = xlsheet.Range("A2: B2000")
      Call range1.Sort(xlsheet.Columns("A"), , , , , , , 1)
      
0
Comment
Question by:jforget1
  • 7
  • 6
  • 2
15 Comments
 

Author Comment

by:jforget1
ID: 12027160
Also does anyone know how to get both values on a checkbox to export to a spreadsheet. I have a field which has both items selected but only the first value is exporting.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12027196
It should be like this

     Call range1.Sort(xlsheet.Range("A1"), xlsheet.Range("B1"))

~Hemanth
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12027208
jforget1,
> Also does anyone know how to get both values on a checkbox to export
> to a spreadsheet. I have a field which has both items selected but only
> the first value is exporting.

No.. you can't ! The checkbox might contain multi values.. but those are selected are the one associated for that doc. You can set another field which lists all the choices and use that to export
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12027289
Second column is sorted like this:
   Call range1.Sort(xlsheet.Columns("A"), , xlsheet.Columns("B"), , , , , 1)

0
 

Author Comment

by:jforget1
ID: 12027295
It is still not sorting by the B column.

As far as the second item, the field can have 2 values, can't it pull both if selected? It is column C, the peripherals field.  

here is all the code

Sub Click(Source As Button)
      
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim db As NotesDatabase
      Dim view As NotesView
      
      Dim Mgrdc As NotesDocumentcollection
      Dim MgrDoc As notesDocument
      
      Dim Repdc As NotesDocumentCollection    
      Dim RepDoc As NotesDocument
      Dim mgrview As NotesView    
      Dim RepView As NotesView
      Dim txt_Agency As String  
      Dim tmp_NotesName As NotesName
      Dim MgrKey, RepKey, ADKey As String
      
      Dim xlApp As Variant
      Dim xlSheet As Variant
      Dim i As Integer
      Dim x As Integer
      Set db = session.CurrentDatabase
      Set Mgrdc = db.UnprocessedDocuments
      Set Mgrdoc = Mgrdc.GetFirstDocument
      On Error Resume Next
      
      RepKey = "ibpc_order_form"         
      
      Set Repview = db.GetView( "(approved)")  
      Set RepDoc  = Repview.GetDocumentByKey( RepKey )    ' form name must be first colum and sorted
      
      Print "Creating Excel Workbook..."
      Set xlApp = CreateObject("Excel.application")
      Print "Creating Excel Worksheet for Refresh..."
      xlApp.Workbooks.Add
      Set xlSheet = xlApp.Workbooks(1).Worksheets(1)
      
      XlApp.Columns("A").Select
      With XlApp.Selection
            .ColumnWidth=6
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("B").Select
      With XlApp.Selection
            .ColumnWidth=6
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("C").Select
      With XlApp.Selection
            .ColumnWidth=10
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("D").Select
      With XlApp.Selection
            .ColumnWidth=15
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("E").Select
      With XlApp.Selection
            .ColumnWidth=30
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("F").Select
      With XlApp.Selection
            .ColumnWidth=15
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("G").Select
      With XlApp.Selection
            .ColumnWidth=12
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("H").Select
      With XlApp.Selection
            .ColumnWidth=5
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("I").Select
      With XlApp.Selection
            .ColumnWidth=6
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      XlApp.Columns("J").Select
      With XlApp.Selection
            .ColumnWidth=10
            .WrapText=1
            .HorizontalAlignment = xlCenter
      End With
      
      xlSheet.Cells(1,1).Value = "Office"     ' change your column headings
      xlSheet.Cells(1,2).Value = "Model"
      xlSheet.Cells(1,3).Value = "Peripherals"
      xlSheet.Cells(1,4).Value = "Contact"
      xlSheet.Cells(1,5).Value = "Address"
      xlSheet.Cells(1,6).Value = "Address2"
      xlSheet.Cells(1,7).Value = "City"
      xlSheet.Cells(1,8).Value = "State"
      xlSheet.Cells(1,9).Value = "Zip"
      xlSheet.Cells(1,10).Value = "Cost Center"
      
      x = 3
      While Not ( RepDoc Is Nothing )                 ' as long as it has a handle on a document do the following
            If  RepDoc.Form(0) = "ibpc_order_form" Then               
                  
                  xlSheet.Rows("1:1").Select                  
                  xlSheet.Rows(1).WrapText =True
                  
                  xlSheet.Cells(x,1).Value = RepDoc.office_num_adjusted
                  xlSheet.Cells(x,2).Value = RepDoc.model
                  xlSheet.Cells(x,3).Value = RepDoc.peripherals
                  xlSheet.Cells(x,4).Value = RepDoc.contact
                  xlSheet.Cells(x,5).Value = RepDoc.address
                  xlSheet.Cells(x,6).Value = RepDoc.address2
                  xlSheet.Cells(x,7).Value = RepDoc.city
                  xlSheet.Cells(x,8).Value = RepDoc.state
                  xlSheet.Cells(x,9).Value = RepDoc.zip
                  xlSheet.Cells(x,10).Value = RepDoc.ccc                  
                  
                  RecNum = x - 3 ' optional
                  Print "Gathering Data.  Record Number: " + RecNum  ' optional
                  x = x + 1                    
            Else                                    
                  Set RepDoc = Repview.GetLastDocument                  ' While not (RepDoc) is nothing
            End If                  
            Set RepDoc = Repview.GetNextDocument(RepDoc)
      Wend
      
      Print "Data Collection Complete."
      
      Set xlSheet = xlApp.Workbooks(1).Worksheets("Sheet1")
      Set range1 = xlsheet.Range("A2: J2000")
      Call range1.Sort(xlsheet.Range("A1"), xlsheet.Range("B1"))
      
      
      Msgbox "Your Refresh Report is ready in Excel. Click OK and then open the Excel file flashing near the bottom of your screen.  ", 64, "Excel Export"
      
      xlApp.Visible = True
      xlApp.UserControl = True
End Sub
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12027318
The second postional parameter is for first column's sort direction and is default to: Ascending
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 12027331
Change it to:
    Call range1.Sort(xlsheet.Range("A1"), , xlsheet.Range("B1"))
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 63

Expert Comment

by:Zvonko
ID: 12027344
If the Designer does not accept that, then try this:
   Call range1.Sort(xlsheet.Range("A1"), Null, xlsheet.Range("B1"))

0
 

Author Comment

by:jforget1
ID: 12027371
Zvonko, that fixed it. Do you know how I can have 2 values from a single checkbox item export to the sheet?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12027456
Which one was the fix? The one with the Null?

And for the checkbox Items do as for all other items. All values will be put in the single destination Excel cell.

0
 

Author Comment

by:jforget1
ID: 12027536
It was the first  without the Null.

For the second item, can I make another column and have the second value fill their?
0
 

Author Comment

by:jforget1
ID: 12027624
Figured out the checkbox feed. THanks for the help.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12028112
Thanks for the points.
But why didn't you post your solution about checkboxes?
I assume it is like this:
xlSheet.Cells(x,11).Value = RepDoc.chkBox(0)
xlSheet.Cells(x,12).Value = RepDoc.chkBox(1)

0
 

Author Comment

by:jforget1
ID: 12028744
Yes you are right I should have posted it and that is what I did.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12028765
Its ok. Thanks for the feedback.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now