SQL on excel sheet.

shivamfet

New Member
Joined
Jul 5, 2011
Messages
1
I have some raw data in excel sheet with the first row is header row..now how should i apply sql on it...i am using excel 2003..if i use data->table option it asks for row and column input..and i am unable to understand that...plz help...
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Change "Sheet1" to actual name.
Add reference:
Tools -> References -> Microsoft ActiveX Data Objects 2.8 (or 2.6) library.
Code:
[COLOR="Blue"]Option[/COLOR] [COLOR="Blue"]Explicit[/COLOR]
[COLOR="Blue"]Option[/COLOR] [COLOR="Blue"]Compare[/COLOR] [COLOR="Blue"]Text[/COLOR]

[COLOR="Blue"]Sub[/COLOR] GetData()

    [COLOR="Blue"]Dim[/COLOR] cn [COLOR="Blue"]As[/COLOR] ADODB.Connection
    [COLOR="Blue"]Dim[/COLOR] rs [COLOR="Blue"]As[/COLOR] ADODB.Recordset

    [COLOR="Blue"]Dim[/COLOR] sSQL [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] sDatabaseFile [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]

    sDatabaseFile = ThisWorkbook.FullName

    [COLOR="Blue"]Set[/COLOR] cn = [COLOR="Blue"]New[/COLOR] ADODB.Connection
    
    [COLOR="Blue"]With[/COLOR] cn
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & sDatabaseFile & ";" & _
                            "Extended Properties=""Excel 8.0 Xml;HDR=Yes;IMEX=1;"";"
        .CursorLocation = adUseClient
        .Mode = adModeRead
        .Open
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
    sSQL = "SELECT * FROM [Sheet1$];"
    
    ' Setup record set.
    [COLOR="Blue"]Set[/COLOR] rs = [COLOR="Blue"]New[/COLOR] ADODB.Recordset

    [COLOR="Blue"]With[/COLOR] rs
        .Source = sSQL
        .ActiveConnection = cn
        .CursorType = adOpenForwardOnly
        .LockType = adLockReadOnly
        .Open Options:=adCmdText
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
    [COLOR="Blue"]With[/COLOR] Sheets("Sheet2")
        .Range("A1").CopyFromRecordset rs
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
      
    rs.Close
    cn.Close
    [COLOR="Blue"]Set[/COLOR] rs = [COLOR="Blue"]Nothing[/COLOR]
    [COLOR="Blue"]Set[/COLOR] cn = [COLOR="Blue"]Nothing[/COLOR]

[COLOR="Blue"]Exit[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top