VBA, Runtime Error 1004, Application defined or Object-defined error

Cassius

New Member
Joined
Apr 15, 2019
Messages
5
Hello,

I'm a beginner in need of some help please (Excel 2013).

I have the below code which loops through the first sheet (Input) taking the value on the 1st row and the value on the first column where there is an intersecting "X" and pasting them into the second sheet (Output).

The code worked well until the first sheet grew and now I have to split the sheet into 3 and run separately otherwise I get a Runtime Error 1004, Application defined or Object-defined error.

I thought I could just define the LastRow and Column as Long but that doesnt seem to work. The error is in the line starting with 'Range'.

Any help is appreciated.

Thank you.

Code:
Sub Newest()


Dim LastRow As Long
Dim LastCol As Long


With ActiveWorkbook.Sheets("Input")


LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
inarr = Range(.Cells(1, 1), .Cells(LastRow, LastCol))


End With
With Worksheets("Output")
Range(.Cells(1, 1), .Cells(LastRow * LastCol, 2)) = ""
outarr = Range(.Cells(1, 1), .Cells(LastRow * LastCol, 2))
indi = 1
For i = 2 To LastCol
 For j = 2 To LastRow
   If inarr(j, i) = "X" Then
    outarr(indi, 1) = inarr(1, i)
    outarr(indi, 2) = inarr(j, 1)
    indi = indi + 1
   End If
 Next j
Next i


Range(.Cells(1, 1), .Cells(LastRow * LastCol, 2)) = outarr


End With
End Sub
 
You're welcome & thanks for the feedback
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,420
Messages
6,124,800
Members
449,189
Latest member
kristinh

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