Transposing Data - Evaluating formula to an array error.

HighAndWilder

Well-known Member
Joined
Nov 4, 2006
Messages
702
Office Version
  1. 365
Platform
  1. Windows
I'm just enhancing my skills and I have hit a problem.

The formula that I write to the workbook evaluates fine but when I try to assign the values to an array I get an error 13 Type Mismatch.

arr = Application.Evaluate(strFormula)

This is Work In Progress but if doing this is not possible than I will adopt a different approach.

What am I missing?

Thanks

VBA Code:
Public Sub subTestCode()
Dim strFormula As String
Dim Q As String
Dim strSplit As String
Dim strFormat As String
Dim WsSource As Worksheet
Dim WsDestination As Worksheet
Dim arr() As Variant

  ActiveWorkbook.Save

  Q = Chr(34)

  Set WsSource = Worksheets("TestData")
  
  Set WsDestination = Worksheets("Sheet9")
  
  WsDestination.Cells.Clear
  
  strSplit = "Column 4"

  strFormat = "DD/MM/YYYY"
  
  strFormula = "LET(allcells,TestData!1:1048576,rows,COUNTA(TestData!$A:$A),cols,COUNTA(TestData!$1:$1),vsplit," & _
  "MATCH(" & Q & strSplit & Q & ",TestData!$1:$1),valuecols,cols-vsplit,HSTACK(" & _
  "CHOOSEROWS(TRANSPOSE(TEXT(INDEX(TestData!$1:$1,1,vsplit+1):INDEX(TestData!$1:$1,1,cols)," & Q & "DD/MM/YYYY" & Q & "))," & _
  "MOD(SEQUENCE(valuecols*(rows-1),,0),valuecols)+1),CHOOSEROWS(INDEX(allcells,2,1):INDEX(allcells,rows,vsplit),MOD(SEQUENCE(valuecols*(" & _
  "rows-1),,0),(rows-1))+1),TOCOL(INDEX(allcells,2,5):INDEX(allcells,rows,cols))))"

  arr = Application.Evaluate(strFormula)
  
  WsDestination.Range("A1").Formula2 = "=" & strFormula
  
End Sub

Transpose Data.xlsm
ABCDEFGH
1Column 1Column 2Column 3Column 401/01/202402/01/202403/01/202404/01/2024
2Dummy 2 1Dummy 2 2Dummy 2 3Dummy 2 41836
3Dummy 3 1Dummy 3 2Dummy 3 3Dummy 3 491094
4Dummy 4 1Dummy 4 2Dummy 4 3Dummy 4 48598
5Dummy 5 1Dummy 5 2Dummy 5 3Dummy 5 41799
6Dummy 6 1Dummy 6 2Dummy 6 3Dummy 6 41169
7Dummy 7 1Dummy 7 2Dummy 7 3Dummy 7 41596
8Dummy 8 1Dummy 8 2Dummy 8 3Dummy 8 45266
TestData


Transpose Data.xlsm
ABCDEF
101/01/2024Dummy 2 1Dummy 2 2Dummy 2 3Dummy 2 41
202/01/2024Dummy 3 1Dummy 3 2Dummy 3 3Dummy 3 48
303/01/2024Dummy 4 1Dummy 4 2Dummy 4 3Dummy 4 43
404/01/2024Dummy 5 1Dummy 5 2Dummy 5 3Dummy 5 46
501/01/2024Dummy 6 1Dummy 6 2Dummy 6 3Dummy 6 49
602/01/2024Dummy 7 1Dummy 7 2Dummy 7 3Dummy 7 410
703/01/2024Dummy 8 1Dummy 8 2Dummy 8 3Dummy 8 49
804/01/2024Dummy 2 1Dummy 2 2Dummy 2 3Dummy 2 44
901/01/2024Dummy 3 1Dummy 3 2Dummy 3 3Dummy 3 48
1002/01/2024Dummy 4 1Dummy 4 2Dummy 4 3Dummy 4 45
1103/01/2024Dummy 5 1Dummy 5 2Dummy 5 3Dummy 5 49
1204/01/2024Dummy 6 1Dummy 6 2Dummy 6 3Dummy 6 48
1301/01/2024Dummy 7 1Dummy 7 2Dummy 7 3Dummy 7 41
1402/01/2024Dummy 8 1Dummy 8 2Dummy 8 3Dummy 8 47
1503/01/2024Dummy 2 1Dummy 2 2Dummy 2 3Dummy 2 49
1604/01/2024Dummy 3 1Dummy 3 2Dummy 3 3Dummy 3 49
1701/01/2024Dummy 4 1Dummy 4 2Dummy 4 3Dummy 4 41
1802/01/2024Dummy 5 1Dummy 5 2Dummy 5 3Dummy 5 41
1903/01/2024Dummy 6 1Dummy 6 2Dummy 6 3Dummy 6 46
2004/01/2024Dummy 7 1Dummy 7 2Dummy 7 3Dummy 7 49
2101/01/2024Dummy 8 1Dummy 8 2Dummy 8 3Dummy 8 41
2202/01/2024Dummy 2 1Dummy 2 2Dummy 2 3Dummy 2 45
2303/01/2024Dummy 3 1Dummy 3 2Dummy 3 3Dummy 3 49
2404/01/2024Dummy 4 1Dummy 4 2Dummy 4 3Dummy 4 46
2501/01/2024Dummy 5 1Dummy 5 2Dummy 5 3Dummy 5 45
2602/01/2024Dummy 6 1Dummy 6 2Dummy 6 3Dummy 6 42
2703/01/2024Dummy 7 1Dummy 7 2Dummy 7 3Dummy 7 46
2804/01/2024Dummy 8 1Dummy 8 2Dummy 8 3Dummy 8 46
Sheet9
Cell Formulas
RangeFormula
A1:F28A1=LET(allcells,TestData!1:1048576,rows,COUNTA(TestData!$A:$A),cols,COUNTA(TestData!$1:$1),vsplit,MATCH("Column 4",TestData!$1:$1),valuecols,cols-vsplit,HSTACK(CHOOSEROWS(TRANSPOSE(TEXT(INDEX(TestData!$1:$1,1,vsplit+1):INDEX(TestData!$1:$1,1,cols),"DD/MM/YYYY")),MOD(SEQUENCE(valuecols*(rows-1),,0),valuecols)+1),CHOOSEROWS(INDEX(allcells,2,1):INDEX(allcells,rows,vsplit),MOD(SEQUENCE(valuecols*(rows-1),,0),(rows-1))+1),TOCOL(INDEX(allcells,2,5):INDEX(allcells,rows,cols))))
Dynamic array formulas.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Not exactly sure on what you're trying to do here but change your arr() declaration to
VBA Code:
Dim arr
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top