Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cycling through Excel using VB 2003 to find duplicates

Cycling through Excel using VB 2003 to find duplicates

Scheduled Pinned Locked Moved Visual Basic
6 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swisher24
    wrote on last edited by
    #1

    I'm using VB 2003 to extract data from an excel file but I'm having trouble looping through one column to find duplicates and counting how may times a cell value is duplicated :confused:. If any one can please feel free to post. :-D

    Swish

    P 1 Reply Last reply
    0
    • S Swisher24

      I'm using VB 2003 to extract data from an excel file but I'm having trouble looping through one column to find duplicates and counting how may times a cell value is duplicated :confused:. If any one can please feel free to post. :-D

      Swish

      P Offline
      P Offline
      petersgyoung
      wrote on last edited by
      #2

      You do not need to loop through the column. A more efficient way is to connect to your excel file with OledbConnection and issue a SQL group by statement.

      petersgyoung

      S 1 Reply Last reply
      0
      • P petersgyoung

        You do not need to loop through the column. A more efficient way is to connect to your excel file with OledbConnection and issue a SQL group by statement.

        petersgyoung

        S Offline
        S Offline
        Swisher24
        wrote on last edited by
        #3

        I'm connecting to the excel file but having trouble with the SQL group by statement. I'm getting an error when the dataset is being filled by the OLEAdapter; An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in microsoft.visualbasic.dll Below is a sample of the code: Dim ex As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & xlfile & ";" & "Extended Properties=Excel 8.0;" Dim conn1 As New OleDbConnection(ex) Dim dtset1 = New DataSet Dim col1 As String = "sc_typname" '<-----Column to group by Dim MyCommand1 As New OleDbDataAdapter("select * from [flnme$] Group By col1", conn1) MyCommand1.Fill(dtset1) DataGrid1.DataSource = dtset1.Tables(0) conn1.Close() Am I missing any information or how can resolve this error? Swish

        P 1 Reply Last reply
        0
        • S Swisher24

          I'm connecting to the excel file but having trouble with the SQL group by statement. I'm getting an error when the dataset is being filled by the OLEAdapter; An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in microsoft.visualbasic.dll Below is a sample of the code: Dim ex As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & xlfile & ";" & "Extended Properties=Excel 8.0;" Dim conn1 As New OleDbConnection(ex) Dim dtset1 = New DataSet Dim col1 As String = "sc_typname" '<-----Column to group by Dim MyCommand1 As New OleDbDataAdapter("select * from [flnme$] Group By col1", conn1) MyCommand1.Fill(dtset1) DataGrid1.DataSource = dtset1.Tables(0) conn1.Close() Am I missing any information or how can resolve this error? Swish

          P Offline
          P Offline
          petersgyoung
          wrote on last edited by
          #4

          Please try this: Dim MyCommand1 As New OleDBDataAdapter("select " & col1 & ", count(*) As [Count] from [flnme$] group by " & col1, conn1)

          petersgyoung

          S 1 Reply Last reply
          0
          • P petersgyoung

            Please try this: Dim MyCommand1 As New OleDBDataAdapter("select " & col1 & ", count(*) As [Count] from [flnme$] group by " & col1, conn1)

            petersgyoung

            S Offline
            S Offline
            Swisher24
            wrote on last edited by
            #5

            I tried working the sql statement you posted and I still receive the Unhandled Exception Error. I've even tried tweaking it by taking the "group by" out of the statement. But I'm going to continue to tweek the code maybe VB 2003 doesn't like something about the statement.

            Swish

            P 1 Reply Last reply
            0
            • S Swisher24

              I tried working the sql statement you posted and I still receive the Unhandled Exception Error. I've even tried tweaking it by taking the "group by" out of the statement. But I'm going to continue to tweek the code maybe VB 2003 doesn't like something about the statement.

              Swish

              P Offline
              P Offline
              petersgyoung
              wrote on last edited by
              #6

              "Group by" should work. Very likely, your statement cannot find something in your Excel, e.g. Table Name, Column Name, File Location, etc. The easiest way for me to help you is to get a copy of your Excel file. My email address is petersgyoung@hotmail.com.

              petersgyoung

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups