'Type mismatch' error in array formula

NettyBetty

New Member
Joined
May 14, 2015
Messages
1
Hello,

I need the below code to count the number of columns in a worksheet and extend an array formula to look at all of those columns. I know there is a 255 character limit with arrays so I've tried to break it in to smaller chunks. I'm getting a 'Type mismatch' error and it's breaking at the .Replace V_V() part.
Any help on why I'm seeing this would be appreciated.

Sub Schedule_Holidays()
' Sets the workbook to R1C1
' Sets the workbook to Manual Calculation mode
' Counts the number of columns in the Holiday Lookup tab and extends the array formulas to match
' Sets the workbook back to Automatic Calculation mode

Dim z As Integer
Dim sWorkSheet As Excel.Worksheet
Dim ArrayPart1 As String
Dim ArrayPart2 As String
Dim ArrayPart3 As String
Dim Stub As String
Set sWorkSheet = Worksheets("Holiday Lookup")

'Sets the workbook to R1C1
Application.ReferenceStyle = xlR1C1

'The array formula must be broken in 3 as it exceeds 255 chrs
Stub = "V_V()" & _
"X_X()" & _
"Y_Y()"
ArrayPart1 = "=IFERROR(IF(R[4]C[11]>=R[4]C[72],(IF(R[4]C[10]<=R[4]C[71],((NETWORKDAYS(R[4]C[71],R[4]C[72],IF(ISNUMBER('Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "]),'Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "]),1))*R[4]C[9])/5*R[4]C[7]),(IF(R[4]C[10]>R[4]C[71],IF(R[4]C[10]>R4C[72],0,((NETWORKDAYS(R[4]C[10],R[4]C[72],IF(ISNUMBER('Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "])),'Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "]),1))*R[4]C[9])/5*R[4]C[7]))))))"
ArrayPart2 = ",(IF(K4>=BU4,(IF(J4<BU4,((NETWORKDAYS(BU4,K4,IF(ISNUMBER('Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "])),'Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "]),1))*I4)/5*G4),"
ArrayPart3 = "(IF(J4>=BU4,((NETWORKDAYS(J4,K4,IF(ISNUMBER('Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "])),'Holiday Lookup'!R[2]C[2]:R[2]C[" & z & "],1)))*I4)/5*G4)))))))),"")"

'Manual calculation
Application.Calculation = xlCalculationManual

' Count number of rows
z = sWorkSheet.Cells(1, Columns.Count).End(xlToRight).Column

' Write to Schedule
With Worksheets("Schedule").Cells(4, 12)
.FormulaArray = Stub
.Replace "V_V()", ArrayPart1
.Replace "X_X()", ArrayPart2
.Replace "Y_Y()", ArrayPart3
End With
Worksheets("Schedule").Range(Cells(4, 12), Cells(65, 12)).FillDown

'Sets the workbook back to A1
Application.ReferenceStyle = xlA1

'Automatic calculation
Application.Calculation = xlCalculationAutomatic



End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,215,343
Messages
6,124,405
Members
449,157
Latest member
mytux

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