Unable to set the FormulaArray property of a range class

DRV21

New Member
Joined
Aug 3, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I have the following formula which i know it exceeds 255 characters but i dont know how to divide it in order to be valid.

Ill attach the macro for a better understanding :



Sub Macro2()

Dim playerReportSheet As Worksheet

Set playerReportSheet = ThisWorkbook.Worksheets("Player report")
Dim formulaPart1 As String
formulaPart1 = "=IF(('All transactions'!$C$3:C10000>='Player report'!F3)*('All transactions'!$C$3:C10000<'Player report'!F4)*('All transactions'!$B$3:B10000>='Player report'!$C$2)*('All transactions'!$B$3:B10000<'Player report'!$E$2),'All transactions'!$L$3:L10000)"
playerReportSheet.Range("G3").FormulaArray = formulaPart1
playerReportSheet.Range("G3").AutoFill Destination:=playerReportSheet.Range("G3:G26")
playerReportSheet.Range("G3:H26").NumberFormat = "#,##0.00"
playerReportSheet.Range("I3:I26").NumberFormat = "[Red]#,##0.00;[Color10]#,##0.00;General"
End Sub

I know there's a way by using replace but i couldn't divide the formula in order to be valid. If there's someone who can help, please.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
VBA Code:
Sub Macro2()

Dim playerReportSheet As Worksheet

Set playerReportSheet = ThisWorkbook.Worksheets("Player report")
Dim formulaPart1 As String
formulaPart1 = "=SUM(IF(('All transactions'!$C$3:C10000>='Player report'!F3)*('All transactions'!$C$3:C10000<'Player report'!F4)*('All transactions'!$B$3:B10000>='Player report'!$C$2)*('All transactions'!$B$3:B10000<'Player report'!$E$2),'All transactions'!$L$3:L10000))"
playerReportSheet.Range("G3").FormulaArray = formulaPart1
playerReportSheet.Range("G3").AutoFill Destination:=playerReportSheet.Range("G3:G26")
playerReportSheet.Range("G3:H26").NumberFormat = "#,##0.00"
playerReportSheet.Range("I3:I26").NumberFormat = "[Red]#,##0.00;[Color10]#,##0.00;General"
End Sub

Updated formula, i misscopied.
 
Last edited by a moderator:
Upvote 0
Hi & welcome to MrExcel.
As the formula is going on the "Player Report" sheet use
VBA Code:
"=SUM(IF(('All transactions'!$C$3:C10000>=F3)*('All transactions'!$C$3:C10000<F4)*('All transactions'!$B$3:B10000>=$C$2)*('All transactions'!$B$3:B10000<$E$2),'All transactions'!$L$3:L10000))"
You should never refer to the name of the sheet the formula is on as it can cause problems.

Also in future when posting code, please use code tags, not quotes. How to Post Your VBA Code
 
Upvote 0
Hi & welcome to MrExcel.
As the formula is going on the "Player Report" sheet use
VBA Code:
"=SUM(IF(('All transactions'!$C$3:C10000>=F3)*('All transactions'!$C$3:C10000<F4)*('All transactions'!$B$3:B10000>=$C$2)*('All transactions'!$B$3:B10000<$E$2),'All transactions'!$L$3:L10000))"
You should never refer to the name of the sheet the formula is on as it can cause problems.

Also in future when posting code, please use code tags, not quotes. How to Post Your VBA Code
Hello, indeed that did the trick by lowering the nr of characters. Easy solution which ofc i didnt thought.

Thank you and yes, i'll use code tag for future posts.
 
Upvote 0
Thinking about it, if every one who uses that workbook is using 2012 or 365 you could use
VBA Code:
Sub Macro2()

With ThisWorkbook.Worksheets("Player report")
   .Range("G3:G26").Formula2 = "=SUM(IF(('All transactions'!$C$3:C10000>=F3)*('All transactions'!$C$3:C10000<F4)*('All transactions'!$B$3:B10000>=$C$2)*('All transactions'!$B$3:B10000<$E$2),'All transactions'!$L$3:L10000))"
   .Range("G3:H26").NumberFormat = "#,##0.00"
   .Range("I3:I26").NumberFormat = "[Red]#,##0.00;[Color10]#,##0.00;General"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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