Sub transform2Query()
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim Current As Worksheet
Dim ar()
Dim i As Long, j As Long, m As Long, n As Long
'cAddr = Array("F2", "B2", "Tab", "I2", "L2", "A5", "B5", "C5", "D5", "A6", "B6", "C6", "D6", "A7", "B7", "C7", "D7", "D16", "D17", "D18", "D19", "I4", "J5", "J7", "J8")
Application.ScreenUpdating = False
Dim strFilename As String: strFilename = "Ideal Queary Layout.xlsx"
Set wb1 = ThisWorkbook
wb1.Activate
Set ws1 = Worksheets("Sheet1")
strFilename = "C:\Users\Owner\Desktop\BDS_Example_PowQuery.xlsx"
Set wb2 = Workbooks.Open(Filename:=strFilename)
wb2.Activate
n = 0
For Each Current In Worksheets ' Loop through all of the worksheets in the active workbook.
' MsgBox Current.Name
If Left(Current.Name, 11) <> "Brew Data B" Then Exit For
Current.Activate
n = n + 1
ReDim Preserve ar(1 To 25, 1 To n)
Batch_no = Right([B2], 1)
ar(1, n) = [F2] ' Date
ar(2, n) = [B2] ' Beer Brand
ar(3, n) = Batch_no ' Batch Number
ar(4, n) = [I2] ' Fermenter
ar(5, n) = [L2] ' Brewers
m = 6
For i = 5 To 7 ' Company / Malt / Location / Amount
If Cells(i, 1) <> "" Then
For j = 1 To 4
ar(m, n) = Cells(i, j)
m = m + 1
Next j
End If
Next i
For i = 1 To 4 ' Minerals
ar(m, n) = Cells(i + 15, 4)
m = m + 1
Next i
ar(22, n) = [I4] ' Start Mash
ar(23, n) = [I5] ' End Mash
ar(24, n) = [I7] ' Strike Temp - Steeping
ar(25, n) = [I8] ' Strike Temp - Mash
Next Current
With wb1
ws1.Range("A15").Resize(UBound(ar, 2), UBound(ar, 1)) = Application.Transpose(ar)
End With
Application.ScreenUpdating = True
wb1.Activate
End Sub
I am a novice re PQ but I doubt if this can be done with PQ which works from structured tables.
Bookmarks