I replied in an earlier question....probably withing the past week, to a
query whereby I sent code in that selects unique items from a column in an
excel database, then returns all the data , per item into a new sheet, with
the sheet name = item.
fyi here is the code, but you should search for the query to put it into
context
1) The file exceldatabase.xls has a table, rangenamed "testdata" with
several columns of data, one column is PROD. Please create a file like this.
How many other columns doesn't matter , so long as one is geaded PROD and teh
range is defined. The code witj get unique values from thi scolumn, so be
sure that whatever values you have, would be ok as sheet tab names - I didn't
bother with error handling to avoid clutter
2) open a new excel workbook and put this code into a standard module -
from teh development environment, menu INSERT / Module
Option Explicit
Sub LoadFromExcelDatabase()
Dim Conn As ADODB.Connection
Dim RST As ADODB.Recordset
Dim RST1 As ADODB.Recordset
Dim strConn As String
Dim SQL As String
Dim ws As Worksheet
Dim cl As Long
Dim sExcelSourceFile As String
sExcelSourceFile = "E:\Excel\Excel_database\Testdatabase.xls"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel
8.0;"
strConn = strConn & "Data Source="
strConn = strConn & sExcelSourceFile
Set Conn = New ADODB.Connection
Conn.Open strConn
Set RST = New ADODB.Recordset
Set RST1 = New ADODB.Recordset
SQL = "SELECT DISTINCT [PROD] FROM testdata"
RST.Open SQL, Conn, adOpenStatic
Do Until RST.EOF
SQL = "SELECT * from testdata where [PROD]='" & RST.Fields(0) & "'"
RST1.Open SQL, Conn, adOpenStatic
Set ws = Worksheets.Add
ws.Name = RST.Fields(0)
For cl = 1 To RST1.Fields.Count
ws.Cells(1, cl).Value = RST1.Fields(cl - 1).Name
Next
ws.Range("A2").CopyFromRecordset RST1
RST1.Close
Set ws = Nothing
RST.MoveNext
Loop
RST.Close
Conn.Close
Set RST = Nothing
Set RST1 = Nothing
Set Conn = Nothing
End Sub