Ahojte,
sry za neskoru odpoved ale tiez som toto riesil :)
a Dostal som sa do dvoch zadrhelov:
1. ako spravit Data Connection na isty subor excelu?
2. ked uz sa podari spravit providera ako spojit tieto dve query co som vytvoril?
mozno ze sa to da aj inak napisat ale zaujimal by ma prave toto SQL riesenie
prikladam svoje nedokoncene makro (nechcel by som to riesit s makrom/Power query ale data connection) + subor:
Sub sbADOExample()
Dim sSQLQry As String
Dim ReturnArray
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
DBPath = ThisWorkbook.FullName
sconnect = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath & ";HDR=Yes';"
Conn.Open sconnect
sSQLSting = "SELECT " & _
" [FacilityID]," & _
"MIN([DateFrom]), " & _
"MAX([DateFrom])" & _
"FROM [data$] AS A1 GROUP BY [FacilityID]"
'sSQLSting = "SELECT [a1].[FacilityID], [a1].[DateFrom], [a1].[Status]" & _
' "FROM [data$] AS [a1]" & _
' "INNER JOIN (SELECT [FacilityID], MAX(DateFrom) AS [DateFrom2] FROM [data$] GROUP BY [FacilityID]) AS [a2] ON [a1].[FacilityID] = [a2].[FacilityID] AND [a1].[DateFrom] = [a2].[DateFrom2] "
mrs.Open sSQLSting, Conn
ActiveSheet.Range("F2").CopyFromRecordset mrs
mrs.Close
Conn.Close
End Sub
citovat