Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default subscript out of range (newbie)

ok, im very new, so im learning as i go, i keep getting error "Subscript out
of range"

when i use this, if i watch the sheets, it starts to do what it is supposed
to do, then i get the error..

could someone please help me
---

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default subscript out of range (newbie)

Again, you need to tell us on what line you get the error. Are you stepping
through the code with the F8 key in the VB Editor? You should be...

On Sun, 6 Mar 2005 15:15:03 -0800, Michael A
wrote:

ok, im very new, so im learning as i go, i keep getting error "Subscript out
of range"

when i use this, if i watch the sheets, it starts to do what it is supposed
to do, then i get the error..

could someone please help me
---

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default subscript out of range (newbie)

I'd guess that you have at least one value in B4:B## that has a value that
doesn't correspond to a worksheet name.

Maybe you have a typo or extra spaces (leading/trailing/embedded) that makes
your code fail.



Michael A wrote:

ok, im very new, so im learning as i go, i keep getting error "Subscript out
of range"

when i use this, if i watch the sheets, it starts to do what it is supposed
to do, then i get the error..

could someone please help me
---

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default subscript out of range (newbie)

Ok, i have the code working now, but its not working as intended. i dont get
any errors.. but its not moving all the data, only some of it, the names are
correct, it just dosn't move them. For example, it skips everything on the
"BOB" sheet, even though there is plenty of things that match that criteria,
but the "RES" sheet has everythign move over just fine.. here is the code i
have that produces no errors

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub


"Dave Peterson" wrote:

I'd guess that you have at least one value in B4:B## that has a value that
doesn't correspond to a worksheet name.

Maybe you have a typo or extra spaces (leading/trailing/embedded) that makes
your code fail.



Michael A wrote:

ok, im very new, so im learning as i go, i keep getting error "Subscript out
of range"

when i use this, if i watch the sheets, it starts to do what it is supposed
to do, then i get the error..

could someone please help me
---

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default subscript out of range (newbie)

Any chance that column A is empty on any of those rows?

If it is, then:
destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1, 0)
is going to have trouble.

You may be overwriting the same row again and again and again.

Maybe you could use column B--since you know it's populated:

destination:=Sheets(oCell.Value).Range("B65536").E nd(xlUp).Offset(1, -1)



Michael A wrote:

Ok, i have the code working now, but its not working as intended. i dont get
any errors.. but its not moving all the data, only some of it, the names are
correct, it just dosn't move them. For example, it skips everything on the
"BOB" sheet, even though there is plenty of things that match that criteria,
but the "RES" sheet has everythign move over just fine.. here is the code i
have that produces no errors

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub

"Dave Peterson" wrote:

I'd guess that you have at least one value in B4:B## that has a value that
doesn't correspond to a worksheet name.

Maybe you have a typo or extra spaces (leading/trailing/embedded) that makes
your code fail.



Michael A wrote:

ok, im very new, so im learning as i go, i keep getting error "Subscript out
of range"

when i use this, if i watch the sheets, it starts to do what it is supposed
to do, then i get the error..

could someone please help me
---

Sub CopyToSheets()

Dim rng As Range
Dim oCell As Range

Set rng = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)
For Each oCell In rng
oCell.EntireRow.Copy _
Destination:=Sheets(oCell.Value).Range("A65536").E nd(xlUp).Offset(1,
0)
Next oCell


End Sub


--

Dave Peterson


--

Dave Peterson
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
Subscript out of range OKHM Excel Discussion (Misc queries) 0 August 6th 09 05:18 PM
what does 'Subscript Out of range' mean?? Gary Excel Worksheet Functions 2 March 22nd 07 01:33 AM
Subscript out of Range teresa Excel Programming 4 December 19th 04 07:11 PM
Subscript is out of Range teresa Excel Programming 2 December 19th 04 05:00 PM
Subscript out of range Stacy Haskins[_2_] Excel Programming 4 April 10th 04 05:41 AM


All times are GMT +1. The time now is 01:38 AM.

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

About Us

"It's about Microsoft Excel"