Runtime Error 1004

egoode

New Member
Joined
Mar 31, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm getting the Runtime Error 1004 Application Defined or object defined error but not seeing what is causing the error!

Dim ExcelFile As Workbook
Dim CRrow As Long
Dim PRrow As Long


Set ExcelFile = ActiveWorkbook

---> I do some code where I open another workbook and copy data across to ExcelFile and then close the other workbook (this is all working as expected)

CRrow = 2

Do Until IsEmpty(ExcelFile.Sheets("CurrentReport").Range(CRrow, 2)) -----> This is where I'm getting the error but I can't workout what isn't defined
PRrow = 2
Do Until IsEmpty(ExcelFile.Sheets("PreviousReport").Range(PRrow, 1))

If ExcelFile.Sheets("CurrentReport").Range(CRrow, 2) = ExcelFile.Sheets("PreviousReport").Range(PRrow, 1) Then
---> Do some checks
Else
PRrow = PRrow + 1
End If

Loop
CRrow = CRrow + 1
Loop


I'm basically trying to go through one list of data and then compare it to another list of data and when I find the matching ID's do some checks to see if some specific fields have changed and then return a value but it doesn't seem to be picking up the first ID I want to check so I have a feeling my other references later in the code will also have the same issue. I feel like it's related to the ExcelFile variable but not sure what is wrong with it.
 
Range(CRrow, 2) is incorrect syntax
VBA expects Range("B"& CRrow) or Cells(CRrow, 2) instead.
(Similar to other: Range(PRrow,1)
 
Upvote 0
Solution
Thanks after a day spent coding I clearly went blind!

I’ve change to the .Range(“A” & CRrow) reference and that got it working.
 
Upvote 0

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