Help! Run time error 1004, range of object_global failed
Thanks for the help; still don't see the answer.
in the debugger
j is 0
recset.fields.count=4
ww = $a$1
and recset(j).Name='effmonth'
when I position float the cursor over the whole line In the debugger I get
range(ww).Offset(0,j).Value=<Method 'range' of object '_global' failed
Is range($a$1).Offset(0,0) an ok statement?
"JLatham" wrote:
When it bombs out, enter Debug and see what 'j' evaluates to and check to see
what each side of the equation evaluates to - either Offset(0,j) is illegal,
or something is really odd with the recset.Fields.Count value. Since the
second option should, in theory, never be invalid or illegal, I suspect that
you're offsetting into an invalid column. Look at ww at that point, look at
value of j and make sure that the resultant column is legitimate.
"in-over-his-head-bill" wrote:
I am getting the subject line error, but only ocassionally when I run my code
-- and I can't figure out a pattern to when it bombs and when it doesn't.
My code is in workbook 1, I open a user-specified workbook 2, which is the
active workbook when it reaches this sub. I am trying to replace the data in
the user-specified range in workbook 2 with new data from a recordset and
save to the same range name.
savetorange is a public string variable containing the user-specified range
name.
Can anyone see what is wrong with the code below? Thanks.
Public Sub manageoutput_exists()
Dim rngResultSet As Range
Dim ww As Variant
' get upper-left most cell of the current range in workbook 2
ww = Range(savetorange).Cells(1, 1).Address
'delete the range
Range(savetorange).Delete
'add field headers from the results of the sql query
For j = 0 To recset.Fields.Count - 1
-next line bombs
Range(ww).Offset(0, j).Value = recset(j).Name
Next j
'copy the recordset data below the headers
ww = Range(ww).Offset(1, 0).Address
Range(ww).CopyFromRecordset recset
Set rngResultSet = Range(ww).End(xlDown).End(xlToRight).CurrentRegion
rngResultSet.Name = savetorange
ActiveWorkbook.Save
End Sub
|