Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Dynamic Range Offset causing problem with this code

I have a wb with several sheets, each has a dynamic range with a name
CODExx.

The following code - partly from the posts here - works if I have NONE
dynamic range (=offset(sheets......etc)

Public Sub moveplist()
Dim rcnt As Integer
Dim nme As Variant
For Each nme In ActiveWorkbook.Names
If Left(nme.Name, 4) = "CODE" Then
'Debug.Print nme.Name
'Debug.Print Range("nme.Name")
Range(nme.Name).Copy Destination:= _
Worksheets("PTable").Cells(1 + rcnt,
1).Range(Range(nme.Name).Address)
End If
rcnt = rcnt + Range(Range(nme.Name).Address).Rows.Count
Next nme

End Sub

If I use dynamic range I get an error msg
Rune Time error '1004'
Method 'Range' of Object 'Global' failed

Can you help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Dynamic Range Offset causing problem with this code

Arishy,

I couldn't reproduce your error, but I got an error, caused I think by
incrementing the counter outside the If test.

Reversing them solved my error

End If
rcnt = rcnt + Range(Range(nme.Name).Address).Rows.Count

to

rcnt = rcnt + Range(Range(nme.Name).Address).Rows.Count
End If


--
HTH

Bob Phillips

"Arishy" wrote in message
oups.com...
I have a wb with several sheets, each has a dynamic range with a name
CODExx.

The following code - partly from the posts here - works if I have NONE
dynamic range (=offset(sheets......etc)

Public Sub moveplist()
Dim rcnt As Integer
Dim nme As Variant
For Each nme In ActiveWorkbook.Names
If Left(nme.Name, 4) = "CODE" Then
'Debug.Print nme.Name
'Debug.Print Range("nme.Name")
Range(nme.Name).Copy Destination:= _
Worksheets("PTable").Cells(1 + rcnt,
1).Range(Range(nme.Name).Address)
End If
rcnt = rcnt + Range(Range(nme.Name).Address).Rows.Count
Next nme

End Sub

If I use dynamic range I get an error msg
Rune Time error '1004'
Method 'Range' of Object 'Global' failed

Can you help



Reply
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
Offset function problem-Dynamic range MarkM Excel Discussion (Misc queries) 1 November 11th 06 02:41 AM
Problem with Slow ReCalculation of Dynamic Range Using OFFSET Kris_Wright_77 Excel Worksheet Functions 2 November 18th 05 10:18 AM
Dynamic range offset problem! Majeed[_2_] Excel Programming 2 November 8th 04 09:00 PM
Problem with code causing Excel '97 to crash Pozzo[_6_] Excel Programming 0 June 16th 04 08:19 PM
dynamic range without using OFFSET() Andrew[_16_] Excel Programming 1 July 25th 03 01:57 PM


All times are GMT +1. The time now is 12:12 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"