LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Help! Run time error 1004, range of object_global failed

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 3 April 14th 09 10:35 PM
Run-time error 1004 Method "Range of object_global failed [email protected] Excel Programming 5 July 3rd 06 11:08 AM
Run-time error '1004': Method 'Range' of object '_Global' failed Neild Excel Programming 0 February 12th 06 11:43 PM
Run-time error '1004': Method 'Range' of object '_Global' failed Tim Williams Excel Programming 2 February 12th 06 10:01 PM
Select method of range class failed, Run time error 1004 smit127 Excel Programming 1 September 1st 05 12:43 PM


All times are GMT +1. The time now is 10:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"