ADO と Excel で多くのことができます。シート名が 1Hour、4Hour、および 24Hour であるとします。
''http://support.microsoft.com/kb/257819
Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim s As String
Dim i As Integer, j As Integer
''This is not the best way to refer to the workbook
''you want, but it is very convenient for notes
''It is probably best to use the name of the workbook.
strFile = ActiveWorkbook.FullName
''HDR=Yes, the names in the first row of the range
''are used as field (column) names.
''
''This is the ACE / Excel 2007/10 connection string, you can get more
''here : http://www.connectionstrings.com/excel
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
''Late binding, so no reference is needed
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
strSQL = "TRANSFORM Sum(ValX) As SumVal " _
& "SELECT GeneID FROM ( " _
& "SELECT GeneID, '01Hour' As TimeX, Value1 As ValX " _
& "FROM [1Hour$] " _
& "UNION ALL " _
& "SELECT GeneID, '04Hour' As TimeX, Value2 As ValX " _
& "FROM [4Hour$] " _
& "UNION ALL " _
& "SELECT GeneID, '24Hour' As TimeX, Value3 As ValX " _
& "FROM [24Hour$] ) t " _
& "GROUP BY GeneID " _
& "PIVOT TimeX"
rs.Open strSQL, cn, 3, 3
''Pick a suitable empty worksheet for the results
With Worksheets("Sheet4")
For i = 0 To rs.Fields.Count - 1
.Cells(1, i + 1) = rs.Fields(i).Name
Next
.Cells(2, 1).CopyFromRecordset rs
End With
''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Jet/ACE SQL を使用できます。
基本 Microsoft Jet SQL for Access 2000
中級 Microsoft Jet SQL for Access 2000
上級 Microsoft Jet SQL for Access 2000