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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,910
Messages
6,175,320
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