Application-defined or object defined error

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am getting a "Runtime 1004 Error, Application-defined or object defined error" on this line.....

.Range("D2:D" & i).Formula2 = "=INDEX(Data!$A$2:$A$250,(ROWS(Data!$1:1)-1)*8+COLUMNS(Data!A:$A))"

If I comment this line out, the error just moves to the next line which is very similar to this one.

I am stuck because i cant see where the error is. Any guidance is much apprecaited.

Noting that Sheet1 has the name "Data"


Here is an extract of the code.
VBA Code:
ThisWorkbook.Unprotect 1234
Sheet4.Select
With ActiveSheet
     .Unprotect 1234
 
    'Find Last Row on Sheet4
     irow = .Range("A" & Rows.Count).End(xlUp).Row + 1

    'Write formulas into Sheet 4, pulling information from Sheet 1
     If Sheet1.Range("A9").Value <> "EW" Then
         .Range("D2:D" & i).Formula2 = "=INDEX(Data!$A$2:$A$250,(ROWS(Data!$1:1)-1)*8+COLUMNS(Data!A:$A))"
         .Range("E2:E" & i).Formula2 = "=VALUE(MID(INDEX(Data!$A$2:$A$250,(ROWS(Data!$1:1)-1)*8+COLUMNS(Data!A:$B)),4,4))"
         .Range("F2:F" & i).Formula2 = "=INDEX(Data!$A$2:$A$250,(ROWS(Data!$1:1)-1)*8+COLUMNS(Data!A:$C))"
     End If

    .Protect 1234
End With


Thanks for your help :)

PS...if I simply paste the formulas directly into the cell, the formulas work fine.
PPS. I also put a simple test like this in and it worked fine too. =IF(Data!A9<> "EW",INDEX(Data!$A$2:$A$250,(ROWS(Data!$1:1)-1)*8+COLUMNS(Data!A:$A)),"No")
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Oh my, How embarassing is that. If you could see my face now,it would be so red.....What a rooky...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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