Object Required error (then code ok in debugger)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I get an "Object Required" error when i run my code, but if I debug I don't
get the error again.

The user may or may not have defined a number of ranges. I need to perform
a validation check on the ranges that HAVE been defined. Header Ranges have
to be one cell only.

dim HeaderRanges as collection, HeaderRange as range,

Set RNGh1 = .Range("Header1"): Set RNGh2 = .Range("Header2")
Set RNGh3 = .Range("Header3"): Set RNGh4 = .Range("Header4")
'suppose that the user has defined only "Header2" and "Header4"
'then RNGh1 is nothing and RNGh3 is nothing

set HeaderRanges=new collection
HeaderRanges.add RNGh1: HeaderRanges.add RNGh2
HeaderRanges.add RNGh3: HeaderRanges.add RNGh4
'HeaderRanges now contains 2 Nothings and two ranges

For Each HeaderRange In HeaderRanges
If Not HeaderRange Is Nothing Then
If HeaderRange.Rows.Count <> 1 _
Or HeaderRange.Columns.Count <> 1 Then
MsgBox "Header ranges must be single cells": Exit Sub
End If
End If
Next 'error occurs the first time this line is encountered, but not
subsequently



any help much appreciated
Thanks
Rob
 
I just put the code into a new workbook and it works fine. Must either be a
problem with my workbook or a bug in excel...
Thanks anyway
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top