#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default sheets

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default sheets

A range object can not span multiple sheets. The object hierarchy is the
application contains workbooks, workbooks contain sheets, and sheets contain
ranges. In the same way that a sheet object can not span multiple workbooks a
range object can not span multiple sheets.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default sheets

Hi

if = 1 as string It looks like your trying to select "Sheet14. If so try this

Set b = Sheets("sheet" & a & "4").Range(Cells(33, 3), Cells(33, 8))

Mike

"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default sheets

What I am trying to do is copy a range of values in cells to a range in
different worksheet. The name of the worksheet is in one of the cells. I
thought i could make an array to collect the values in the cells then copy
them to another sheet. The array I called 'a'. 'a(4)' contains the name of
the sheet that I want to copy the values to. Does this not work:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

I am trying to set 'b' as the range to copy to.


"Jim Thomlinson" wrote:

A range object can not span multiple sheets. The object hierarchy is the
application contains workbooks, workbooks contain sheets, and sheets contain
ranges. In the same way that a sheet object can not span multiple workbooks a
range object can not span multiple sheets.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default sheets

The range b can only exist on one sheet at a time. It can not span multiple
sheets in the same way that one sheet can not span multiple workbooks. What
you need to do is to copy your range of cells and then paste those to each
target sheet one at a time... Are you only looking to copy the values??? If
so then the code is really very easy as you can just set the values of the
copied range to the destination range something like this...

with sheets("sheet1").range("A1:B1") 'Range to copy
sheets("sheet2").range("A1:B1").Value = .value
sheets("sheet3").range("A1:B1").Value = .value
sheets("sheet3").range("A2:B2").Value = .value
end with
--
HTH...

Jim Thomlinson


"ranswert" wrote:

What I am trying to do is copy a range of values in cells to a range in
different worksheet. The name of the worksheet is in one of the cells. I
thought i could make an array to collect the values in the cells then copy
them to another sheet. The array I called 'a'. 'a(4)' contains the name of
the sheet that I want to copy the values to. Does this not work:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

I am trying to set 'b' as the range to copy to.


"Jim Thomlinson" wrote:

A range object can not span multiple sheets. The object hierarchy is the
application contains workbooks, workbooks contain sheets, and sheets contain
ranges. In the same way that a sheet object can not span multiple workbooks a
range object can not span multiple sheets.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default sheets

Move the "Sheets(a(4))." part inside in front of the "cells(..." like this,

Set b = Range(Sheets(a(4)).Cells(33, 3), Sheets(a(4)).Cells(33, 8))

or
With Sheets(a(4))
set b = range(.cells(33,3),.cells(33,8)
End With

then, of course, a(4) in the a array must contain a string corresponding to
an existing Sheet in the workbook.
The problem with your code is that the Cells(33,3) refers to the active
worsheet, even though you stated the sheet in front of your range. In
principle, what you have been writing is
Set b = Sheets(a(4)).Range(ActiveSheet.cells(33, 3), ActiveSheet.Cells(33,
8))

Your code actually works if you set a(4) to the active workbook before
setting b to your range.

regards,
Lazzzx




"Jim Thomlinson" skrev i
meddelelsen ...
A range object can not span multiple sheets. The object hierarchy is the
application contains workbooks, workbooks contain sheets, and sheets
contain
ranges. In the same way that a sheet object can not span multiple
workbooks a
range object can not span multiple sheets.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to
put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default sheets


Thanks for your help I'll give that a try
"Jim Thomlinson" wrote:

The range b can only exist on one sheet at a time. It can not span multiple
sheets in the same way that one sheet can not span multiple workbooks. What
you need to do is to copy your range of cells and then paste those to each
target sheet one at a time... Are you only looking to copy the values??? If
so then the code is really very easy as you can just set the values of the
copied range to the destination range something like this...

with sheets("sheet1").range("A1:B1") 'Range to copy
sheets("sheet2").range("A1:B1").Value = .value
sheets("sheet3").range("A1:B1").Value = .value
sheets("sheet3").range("A2:B2").Value = .value
end with
--
HTH...

Jim Thomlinson


"ranswert" wrote:

What I am trying to do is copy a range of values in cells to a range in
different worksheet. The name of the worksheet is in one of the cells. I
thought i could make an array to collect the values in the cells then copy
them to another sheet. The array I called 'a'. 'a(4)' contains the name of
the sheet that I want to copy the values to. Does this not work:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

I am trying to set 'b' as the range to copy to.


"Jim Thomlinson" wrote:

A range object can not span multiple sheets. The object hierarchy is the
application contains workbooks, workbooks contain sheets, and sheets contain
ranges. In the same way that a sheet object can not span multiple workbooks a
range object can not span multiple sheets.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default sheets

Take a look at this:
http://www.rondebruin.nl/copy2.htm

I believe you can modify it (slightly) for your purpose.


Regards,
Ryan--


--
RyGuy


"Mike H" wrote:

Hi

if = 1 as string It looks like your trying to select "Sheet14. If so try this

Set b = Sheets("sheet" & a & "4").Range(Cells(33, 3), Cells(33, 8))

Mike

"ranswert" wrote:

I am trying to get a name of a sheet from a cell then go to that sheet to put
data into a range of cells. I get an error on the following code:

Set b = Sheets(a(4)).Range(Cells(33, 3), Cells(33, 8))

'b' is a range and 'a' is an array(1 to 8) as string

What am I doing wrong?

Thanks

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
Print sheets by "All Sheets in workbook, EXCEPT for specific named sheets". Possible? Corey Excel Programming 2 December 11th 06 01:35 AM
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA Amaxwell Excel Worksheet Functions 4 August 17th 06 06:23 AM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Programming 6 March 29th 06 12:43 PM
Macro for filter on protected workbook that works for all sheets, no matter what sheets are named? StargateFanFromWork[_3_] Excel Programming 6 January 26th 06 06:31 PM


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