Object Defined error on Range.Offset

sdohertyccb

Board Regular
Joined
Feb 15, 2005
Messages
91
I must be having a brain cramp on this one, I have not run into this problem before. I am trying to clear contents from a dynamic range in a workbook and I am getting an object defined error. I'm wondering if it is because I declared the "clear_rng" as a range, but don't understand why that would be.
Here is what I have (Highlight is the error):
Code:
Sub get_recon()
Dim gl_filename1 As String
Dim gl_pathname1 As String
Dim gl_filename2 As String
Dim gl_pathname2 As String
Dim lastrow As Integer
Dim file_lastrow As Integer
Dim file_lastcol As Integer
Dim Wkbk As Workbook
Dim r As Range
Dim c As Range
Dim clear_rng As Range
Dim clear_rng_rows As Integer
Dim clear_rng_cols As Integer

Set Wkbk = ThisWorkbook

gl_filename1 = Range("gl_filename1")
gl_pathname1 = Range("gl_pathname1")
gl_filename2 = Range("gl_filename2")
gl_pathname2 = Range("gl_pathname2")
lastrow = Range("recon.lastrow") + 1
clear_rng_rows = Range("clear_rng_rows")
clear_rng_cols = Range("clear_rng_col")
[highlight]clear_rng = Sheets("reconcile").Range(Cells(lastrow, 4)).Offset(clear_rng_rows, clear_rng_cols)[/highlight]

Sheet10.Activate
Range(clear_rng).Select
Selection.ClearContents

Any help you can give is greatly appreciated.
Thanks in advance.
 

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.
You need to Set objects so it should be
Code:
Set clear_rng = Sheets("reconcile").Range(Cells(lastrow, 4)).Offset(clear_rng_rows, clear_rng_cols)
Also this
Code:
Range(clear_rng).Select
Selection.ClearContents
should be
Code:
clear_rng.Select
Selection.ClearContents

or even

clear_rng.ClearContents
 
Upvote 0
Fluff, thanks for the tip. I had used the Set command earlier and got the same error; so I went back and reset that line as you suggest, and I still get the same error.

I modified as follows:
Code:
Set clear_rng = Sheets("reconcile").Cells(lastrow, 4).Offset(clear_rng_rows, clear_rng_cols)

This clears the error, but instead of the range from D254:P314 id get the cell Q314
Where lastrow = 254, clear_rng_rows = 60, and clear rng_cols = 13
 
Last edited:
Upvote 0
In that case you need to sue Resize, not Offset
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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