Run-time error '1004': Application-defined or object-defined error

kaywin

New Member
Joined
Nov 23, 2010
Messages
30
I am getting "Application-defined or object-defined " error with the following code:(Written in ThisWorkbook)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim flag As Variant
flag = False
Set rng = Worksheets("CIRC_BW").Range("A1", Range("A1").End(xlDown))
'Set rng = Worksheets("CIRC_BW").Range("A1:A65536")
For Each cell In rng
If Not IsEmpty(cell) And IsEmpty(cell.Offset(0, 6)) Then
cell.Offset(0, 6).Value = 0
flag = True
End If
Next
End Sub

Can anyone help on this.

Thanks
Kaywin
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Works perfectly here - I get a nice set of zeroes in column G where there's something in A and G doesn't already have a value in it.

Does it give any clue as to which line it's objecting to?
 
Upvote 0
Thanks for your reply .
I am getting this error when i select some other sheet in the same workbook other than "CIRC_BW" and click on save .

Its giving error in the line
Set rng = Worksheets("CIRC_BW").Range("A1", Range("A1").End(xlDown))


Thanks
Kaywin
 
Upvote 0
Hi

You need to fully qualify your ranges:

Code:
With Worksheets("CIRC_BW")
  Set rng = .Range("A1", .Range("A1").End(xlDown))
End With

Note the periods before each Range()
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

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