Michael1984DK
New Member
- Joined
- Apr 30, 2018
- Messages
- 27
Hi. I am trying to do a VBA script that automatically selects today date file in a destination folder and uses this in an array formula.
When typing in the formula in the sheet without VBA this works. (Ctrl + Shift + Enter)
But when typing in and adjusting to select newest file in location I get error message:
"Unable to set FormulaArray property of the Range class"
My VBA script looks as follow:
The path is correct and when doing a MsgBox(D), it shows the correct path and filename + sheet name.
I am unsure what I am missing here since I can't get it to work no matter what I do?
I read about the 255 character limit, but the D string should solve this I assume?
(In my local format settings in Excel, I usually use ; instead of , to split up formulas, FYI, but I have tried both without success - Eg. =LEFT(A1;2) )
I hope someone can help out?
Thank you
When typing in the formula in the sheet without VBA this works. (Ctrl + Shift + Enter)
Code:
=IFERROR(INDEX('[Deliveries - 13.07.2018.xls]Deliveries - 13.07.2018'!$C$6:$C$1000;SMALL(IF('[Deliveries - 13.07.2018.xls]Deliveries - 13.07.2018'!$O$6:$O$1000=$AZ7;ROW('[Deliveries - 13.07.2018.xls]Deliveries - 13.07.2018'!$C$6:$C$1000)-MIN(ROW('[Deliveries - 13.07.2018.xls]Deliveries - 13.07.2018'!$C$6:$C$1000))+1);COLUMNS($AZ$7:AZ7)));"")
But when typing in and adjusting to select newest file in location I get error message:
"Unable to set FormulaArray property of the Range class"
My VBA script looks as follow:
Code:
Sub Macro1()
'
'
Dim D As String, dtOOS As String
dtOOS = Format(Application.WorksheetFunction.WorkDay(Date, 0), "dd.mm.yyyy") ' returns last workday e.g. 01.13
D = "O:\My Drive\CS&L Nordic\Ingoing Deliveries - AllinOne\[Deliveries - " & dtOOS & ".xls]Deliveries - " & dtOOS
'
Range("BA7").Select
Selection.FormulaArray = "=IFERROR(INDEX('" & D & "'!$C$6:$C$1000,SMALL(IF('" & D & "'!$O$6:$O$1000=$AZ7,ROW('" & D & "'!$C$6:$C$1000)-MIN(ROW('" & D & "'!$C$6:$C$1000))+1),COLUMNS($AZ$7:AZ7))),"")"
End Sub
The path is correct and when doing a MsgBox(D), it shows the correct path and filename + sheet name.
I am unsure what I am missing here since I can't get it to work no matter what I do?
I read about the 255 character limit, but the D string should solve this I assume?
(In my local format settings in Excel, I usually use ; instead of , to split up formulas, FYI, but I have tried both without success - Eg. =LEFT(A1;2) )
I hope someone can help out?
Thank you