Hi, I wonder whether someone may be able to help me please.
I'm uising the code below to try and apply, amongst other functionality a formula to a given cell, but I'm having difficulty in applying the formula.
Sub Slide1Format()
Dim LastRow As Long
Application.ScreenUpdating = False
Const StartRow As Long = 5
Sheets("Slide 1").Select
With Range("B2")
.Value = "Monthly Actuals Used"
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 11
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 11
.ColorIndex = 2
End With
End With
With Range("B3")
.Value = Evaluate("EoMonth(Today(), -2) + 1")
.NumberFormat = "mmm yy"
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 37
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 10
End With
End With
With Range("B7").End(xlDown)
With .Offset(7, 0)
.Value = "BAS Consultants"
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 11
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 11
.ColorIndex = 2
End With
End With
With .Offset(2, 0)
.Value = "Total No. of Projects (C&R Only)"
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 37
With .Font
.Name = "Lucida Sans"
.Bold = True
.Size = 10
.ColorIndex = 1
End With
End With
With .Offset(3, 0)
Selection.FormulaArray = "=SUM(IF(FREQUENCY(IF(IFPRLOB=""Consultancy & Requirements"",IF(LEN(IFPPN)>0,MATCH(IFPPN,IFPPN,0),"")), IF(IFPRLOB=""Consultancy & Requirements"",IF(LEN(IFPPN)>0,MATCH(IFPPN,IFPPN,0),"")))>0,1))"
End With
End With
Columns("B:L").AutoFit
End Sub
This is the line of code I'm having difficulty which I've put togther from posts I've read on this and other forums:
With .Offset(3, 0)
Selection.FormulaArray = "=SUM(IF(FREQUENCY(IF(IFPRLOB=""Consultancy & Requirements"",IF(LEN(IFPPN)>0,MATCH(IFPPN,IFPPN,0),"")), IF(IFPRLOB=""Consultancy & Requirements"",IF(LEN(IFPPN)>0,MATCH(IFPPN,IFPPN,0),"")))>0,1))"
End With
Manually entered, the formula works fine, but when I run this I receive the following error:
Run time error '1004' Unable to set the FormulaArray property of the Range Class
I just wondered whether someone could look at this please and let me know where I've gone wrong.
Many thanks and kind regards
Bookmarks