Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using Cells( ) for Range definition

I am trying to write a code using the Cells() for range defintion but
it didn't work. It only works when I use the regular defition [i.e.
Range("A3:D30") instead of Range(Cells(3,1),Cells(30,4))]

Here is what I tried to write:

Sub CopyToSheet1 ()
Dim i As Integer

i = InputBox("Enter Sheet Number (1):")

With ThisWorkbook
For j = 5 TO 10
.Sheets(i).Range(Cells(3,1),Cells(30,4)).Copy
Sheets("Sheet1").Range(Cells(5,1),Cells(32,4))

.Sheets(i).Range(Cells(3,j),Cells(30,j)).Copy
Sheets("Sheet1").Range(Cells(5,j+2),Cells(32,j+2)) .PasteSpecial
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Next j
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using Cells( ) for Range definition

Sub CopyToSheet1 ()
Dim i As Integer
Dim sh as worksheet
Dim sh1 as worksheet

i = InputBox("Enter Sheet Number (1):")

With ThisWorkbook
set Sh = .Sheets(i)
set Sh1 = .Sheets("Sheet1")
For j = 5 TO 10
Sh.Range(Sh.Cells(3,1),Sh.Cells(30,4)).Copy _
Sh1.Range(Sh1.Cells(5,1),sh1.Cells(32,4))

sh.Range(sh.Cells(3,j),sh.Cells(30,j)).Copy _
sh1.Range(sh1.Cells(5,j+2),sh1. Cells(32,j+2)).PasteSpecial _
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Next j
End With
End Sub

The unqualified Cells refers to the activesheet, so you need to qualify them
with the sheet you want.

--
Regards,
Tom Ogilvy

wrote in message
om...
I am trying to write a code using the Cells() for range defintion but
it didn't work. It only works when I use the regular defition [i.e.
Range("A3:D30") instead of Range(Cells(3,1),Cells(30,4))]

Here is what I tried to write:

Sub CopyToSheet1 ()
Dim i As Integer

i = InputBox("Enter Sheet Number (1):")

With ThisWorkbook
For j = 5 TO 10
.Sheets(i).Range(Cells(3,1),Cells(30,4)).Copy
Sheets("Sheet1").Range(Cells(5,1),Cells(32,4))

.Sheets(i).Range(Cells(3,j),Cells(30,j)).Copy
Sheets("Sheet1").Range(Cells(5,j+2),Cells(32,j+2)) .PasteSpecial
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Next j
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using Cells( ) for Range definition

Thanks Tom,

How can I use a variable sheet name instead of the index to refer to the sheets?

With ThisWorkbook
set Sh = .Sheets(i)
set Sh1 = .Sheets(1)
For j = 5 TO 10
Sh.Range(Sh.Cells(3,1),Sh.Cells(30,4)).Copy _
Sh1.Range(Sh1.Cells(5,1),sh1.Cells(32,4))

sh.Range(sh.Cells(3,j),sh.Cells(30,j)).Copy _
sh1.Range(sh1.Cells(5,j+2),sh1. Cells(32,j+2)).PasteSpecial _
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Next j
End With
End Sub

The unqualified Cells refers to the activesheet, so you need to qualify them
with the sheet you want.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using Cells( ) for Range definition

Thanks,

If we have varying number of charts, how can we copy them from one
workbook/sheet to another (where every time we have different number
of Charts)

In the example below, I have 8 charts. In other cases it could be
different (e.g. 6, 7, 13, etc.):
=========
Sh.Shapes.Range(Array("Chart 1", "Chart 2", "Chart 3", "Chart 4" _
, "Chart 5", "Chart 6", "Chart 7", "Chart 8")).Select

Selection.Copy

Sh1.Paste
==========
sName = "Sheet1"
set Sh = .Sheets(sName)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy Charts

Thanks,

but I don't have the charts as sheets. They are embeded in sheets.
"Charts.copy" copies the whole sheet not the charts in the sheet.
If there isn't a simple way to copy a variable number of charts
embeded in a sheet, is there a way to convert the charts from embeded
in a sheet to Chart sheets



Charts.copy

copies all your chart sheets to a new workbook.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using Cells( ) for Range definition

Thanks,

but I don't have the charts as sheets. They are embeded in sheets.
"Charts.copy" copies the whole sheet not the charts in the sheet.
If there isn't a simple way to copy a variable number of charts
embeded in a sheet, is there a way to convert the charts from embeded
in a sheet to Chart sheets

"Tom Ogilvy" wrote in message ...
Charts.copy

copies all your chart sheets to a new workbook.

--
Regards,
Tom Ogilvy

wrote in message
om...
Thanks,

If we have varying number of charts, how can we copy them from one
workbook/sheet to another (where every time we have different number
of Charts)

In the example below, I have 8 charts. In other cases it could be
different (e.g. 6, 7, 13, etc.):
=========
Sh.Shapes.Range(Array("Chart 1", "Chart 2", "Chart 3", "Chart 4" _
, "Chart 5", "Chart 6", "Chart 7", "Chart 8")).Select

Selection.Copy

Sh1.Paste
==========
sName = "Sheet1"
set Sh = .Sheets(sName)

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
VBA Range definition: Code needed David B Excel Discussion (Misc queries) 8 September 25th 06 06:40 PM
f statistic, p value definition Regression analysis terms Excel Worksheet Functions 1 June 8th 06 09:11 PM
$ definition nicolebelle Excel Worksheet Functions 1 November 18th 05 01:44 PM
End of data definition Surfstiling Excel Discussion (Misc queries) 1 March 25th 05 12:56 AM
The definition of.... Ursula Excel Worksheet Functions 2 February 16th 05 04:14 PM


All times are GMT +1. The time now is 09:35 PM.

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"