3 Replies - 281 Views - Last Post: 15 July 2014 - 12:38 AM Rate Topic: -----

#1 vivibuy88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-July 14

Sorting help

Posted 14 July 2014 - 05:48 PM

Please tell me where I did which part I do wrong ?
Sorting error : Unable to cast object of type 'System.String' to type 'System.Array'.


  For row_csv = 3 To toLoop


            unmount = sheet.Cells(row_csv, 8).Value
            If (unmount = Nothing Or unmount = "") Then
                MsgBox(unmount)
                csv_location = sheet.Cells(row_csv, 4).Value
                MsgBox(csv_location)
                Array.Sort(csv_location)    ' Error found !
                csv_location.Sort(Key1:=sheet.Cells(row_csv, 4), Order1:=Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending)
                csv_location_check = sheet.Cells(row_csv, 7).Value
                MsgBox("You are here 1")
            End If
Next 





Is This A Good Question/Topic? 0
  • +

Replies To: Sorting help

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 673
  • View blog
  • Posts: 2,964
  • Joined: 03-December 12

Re: Sorting help

Posted 14 July 2014 - 09:26 PM

My guess would be, trying to sort a cell value like it's an array. What are you trying to sort and why?
Was This Post Helpful? 0
  • +
  • -

#3 vivibuy88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-July 14

Re: Sorting help

Posted 14 July 2014 - 10:09 PM

I want to do comparision between two excel
However one of the excel are not arranged in order. So I have to do sorting first
Currently data : d1 d2 d3 c1 e1 d4 c2 c3 c4
My expected output: c1 c2 c3 c4 d1 d2 d3 d4 e1

Can share with me on how to do sorting ?
Was This Post Helpful? 0
  • +
  • -

#4 vivibuy88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-July 14

Re: Sorting help

Posted 15 July 2014 - 12:38 AM


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

     
        Dim csv_location
        Dim csv_file

        csv_file = csv_txt.Text

        Dim excel As Excel.Application
        Dim book As Excel.Workbook
        Dim sheet As Excel.Worksheet


        excel = CreateObject("Excel.Application")
        book = excel.Workbooks.Open(csv_file)
        sheet = book.Worksheets.Item(1)
        'specify worksheet name 
        excel.Visible = True
        sheet.Range("D1").Select()
        sheet.Range("D1:D2000").Sort(Key1:="D3", Order1:=Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending, _
                                     Header:=Microsoft.Office.Interop.Excel.XlYesNoGuess.xlGuess, OrderCustom:=1, MatchCase:=False, _
                                     Orientation:=Microsoft.Office.Interop.Excel.XlSortOrientation.xlSortColumns, _
                                     DataOption1:=Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal)




        sheet = Nothing
        book.SaveAs("O:\ENG\Dept\04_Common\02_Development_Guidelines\02_PCB\Training_Folder\new.csv")
        book.Close(SaveChanges:=True)
        book = Nothing
        excel.Quit()
        excel = Nothing





is there any one can give me a clue why the column cant be sorted .


Why
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1