I'm trying to write a macro to create a transpose formula for me.
The transpose formula references another workbook, and worksheet and I can't seem to get the syntax right. Here is my code so far.
The problem line is this one:
If I just enter it by hand I get this formula:
What am I missing?
The transpose formula references another workbook, and worksheet and I can't seem to get the syntax right. Here is my code so far.
VBA Code:
Sub buildformulas()
Dim wbname As String
Dim monthname As String
Dim colletter As String
Dim path1 As String
Dim wb2 As Workbook
Dim wb1 As Workbook
Dim ws2 As Worksheet
'Loop for Formulas
Set wb1 = ActiveWorkbook
path1 = "R:\1200\1255\CapacitySurvey_2020\Acct\"
i = 11
wbname = Sheets("Macroinput").Cells(i, 1).Value
Set wb2 = Workbooks.Open(Filename:=path1 & wbname)
For r = 11 To 57
wb1.Activate
monthname = Sheets("Macroinput").Cells(r, 2).Value
colletter = Sheets("Macroinput").Cells(r, 3).Value
wb2.Activate
Set ws2 = wb2.Worksheets(monthname)
wb1.Activate
Cells(r, 11).Formula = "=Transpose('[" & wb2 & "]" & ws2 & "'!$" & colletter & "$21:$" & colletter & "$100)"
Next
End Sub
The problem line is this one:
VBA Code:
Cells(r, 11).Formula = "=Transpose('[" & wb2 & "]" & ws2 & "'!$" & colletter & "$21:$" & colletter & "$100)"
If I just enter it by hand I get this formula:
Excel Formula:
=TRANSPOSE('[Myron Stratton Spring Run Res YE Oct2016.xlsx]December'!$L$21:$L$100)
What am I missing?