Forum

Help with Run-Time ...
 
Notifications
Clear all

Help with Run-Time Error '1004' - when copying sheet macro breaks

5 Posts
2 Users
0 Reactions
77 Views
(@sean)
Posts: 3
Active Member
Topic starter
 

Hi Community, 

Thanks in advance for any help or advise. I have built a macro to add a column on a sheet but I now want to copy that sheet and have the formula reference the new sheet not the old sheet. Here is the formula:
--
Sub Button4_Click()

ActiveSheet.Range("F1").Select
ActiveCell.EntireColumn.Insert shift:=x1Down

ActiveSheet.Range("F2").Select
ActiveCell.Formula = "=IF(INDEX(INPUTS!$H$4:$J$79,MATCH('Example Week'!F4,INPUTS!$H$4:$H$79,0),3)="""","""",INDEX(INPUTS!$H$4:$J$79,MATCH('Example Week'!F4,INPUTS!$H$4:$H$79,0),3))"

End Sub
--

When I copy the sheet the above formula is on the macro still has cell F2 reference 'Example Week' instead of 'Example Week (2)'.

I tried replacing 'Example Week'!F4 with: CONCATENATE("'",MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255),"!'","F4") but that is what gave me the error.

Any ideas / advice would be much appreciated. Thanks

 
Posted : 01/02/2020 12:40 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Sean,

Please supply the workbook with the code/data.

Regards

Phil

 
Posted : 01/02/2020 12:59 am
(@sean)
Posts: 3
Active Member
Topic starter
 

Thanks Phil. Please see attached.

 
Posted : 01/02/2020 1:45 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Sean,

Just remove the reference to the sheet?

=IF(INDEX(INPUTS!$H$4:$J$79,MATCH(F4,INPUTS!$H$4:$H$79,0),3)="""","""", INDEX(INPUTS!$H$4:$J$79,MATCH(F4,INPUTS!$H$4:$H$79,0),3))"

Regards

Phil

 
Posted : 01/02/2020 8:29 pm
(@sean)
Posts: 3
Active Member
Topic starter
 

Thanks Phil ‍♂️

 
Posted : 03/02/2020 3:28 am
Share: