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: 6
Default Run-time error '1004': Method 'Range' of object '_Worksheet'failed... again!

A similar problem to my previous post - this time however the code
fails on the line beneath the 'Copy disease group comment. I'm
providing the whole sub for context. I am copying data from a source
workbook wherein each worksheet relates to an particular disease
group, and within each sheet there are identically spaced ranges (one
for each health region) containing the data of interest.

I am curious as to why this syntax is failing as it would seem to be
identical to that in the Excel 2003 help file under the 'Range
Property' topic, namely:
This example sets the font style in cells A1:C5 on Sheet1 to italic.
The example uses Syntax 2 of the Range property.

Worksheets("Sheet1").Range(Cells(1, 1), Cells(5, 3)). _
Font.Italic = True

===========================================
Sub ExportDataRanges()

Dim SourceSheet As Worksheet
Dim TargetSheet As Worksheet
Dim i As Integer

Set TargetSheet = Application.Workbooks("Summary.xls").Worksheets
("Sheet3")
'Add column headings
TargetSheet.Cells(1, 1).Value = "Disease Group"
TargetSheet.Cells(1, 2).Value = "Health Region"
TargetSheet.Cells(1, 3).Value = "Sex"
TargetSheet.Cells(1, 4).Value = "Year"
TargetSheet.Cells(1, 5).Value = "ASR"
TargetSheet.Cells(1, 6).Value = "ASR LCI"
TargetSheet.Cells(1, 7).Value = "ASR UCI"
TargetSheet.Cells(1, 8).Value = "Cases"
TargetSheet.Cells(1, 9).Value = "Cases LCI"
TargetSheet.Cells(1, 10).Value = "Cases UCI"
'Fill column headings (tan colour)
With TargetSheet.Range(Cells(1, 1), Cells(1, 10)).Interior
.ColorIndex = 40
.Pattern = xlSolid
End With

For Each SourceSheet In Workbooks("T090035N Males.xls").Worksheets
For i = 0 To 11
'Copy disease group
TargetSheet.Range(Cells((i * 39) + 2, 1), Cells((i * 39) + 40,
1)).Value = SourceSheet.Range(Cells((i * 44) + 4, 1)).Value
'Copy health region
TargetSheet.Range(Cells((i * 39) + 2, 2), Cells((i * 39) + 40,
1)).Value = SourceSheet.Range(Cells((i * 44) + 2, 1)).Value
'Gender is male for this workbook
TargetSheet.Range(Cells((i * 39) + 2, 3), Cells((i * 39) + 40,
1)).Value = "Male"
'Copy source data for single health region for years 1998 to
2036
TargetSheet.Range(Cells((i * 39) + 2, 4), Cells((i * 39) + 40,
10)).Value = SourceSheet.Range(Cells((i * 44) + 4, 25), Cells((i * 44)
+ 42, 31)).Value
Next i
Next SourceSheet

Set TargetSheet = Nothing

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': Method 'Range' of object '_Worksheet' failed [email protected] Excel Programming 2 March 6th 09 03:23 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
Run-time error 1004: Method 'Axes' of object '_chart' failed Brian Morrison Excel Programming 0 October 20th 05 03:39 PM
"Run-time error '1004'" Method 'Range' of object '_global' failed. haisat[_2_] Excel Programming 0 October 20th 03 12:13 PM


All times are GMT +1. The time now is 08:58 AM.

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"