#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 78
Default Array

Hi
I am using the formula below to copy a worksheet, which is then pasted out to another workbook.

ThisWorkbook.Worksheets(Array("Tab name")).Copy

is it possible for me to use a cell value instead of having to enter the worksheet name

or

read the Worksheet tab and use this value

thanks

kevin

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,514
Default Array

kevcar40 wrote on 6/8/2011 :
Hi
I am using the formula below to copy a worksheet, which is then pasted out to
another workbook.

ThisWorkbook.Worksheets(Array("Tab name")).Copy

is it possible for me to use a cell value instead of having to enter the
worksheet name

or

read the Worksheet tab and use this value

thanks

kevin


If it's the active sheet:
ThisWorkbook.ActiveSheet.Copy

If several sheets:
Group them first, then use...

ActiveWindow.SelectedSheets.Copy
OR possibly

ThisWorkbook.Sheets(Array(sWksList)).Copy '//not tested

A reusable function for grouping sheets:

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
' GroupSheets()
' This procedure requires only the necessary amount of coding be used
' in the Caller. By default, it requires passing only the first arg.
' Use Example: GroupSheets "Sheet1,Sheet3"
' creates a group of only those sheets.
' To group all sheets in a workbook except those sheets:
' GroupSheets "Sheet1,Sheet3", False
' To group all sheets in a workbook pass an empty string:
' GroupSheets "", False
' You can pass the Wkb arg to specify any open workbook.
' (The Wkb doesn't need to be active for this purpose)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Public Sub GroupSheets(Sheetnames As String, _
Optional bInGroup As Boolean = True, _
Optional Wkb As Workbook)
' Groups sheets in Wkb based on whether Sheetnames
' are to be included or excluded in the grouping.
' Arg1 is a comma delimited string. (ie: "Sheet1,Sheet3")

Dim Shts() As String, sz As String
Dim i As Integer, Wks As Worksheet, bNameIsIn As Boolean

If Wkb Is Nothing Then Set Wkb = ActiveWorkbook
For Each Wks In Wkb.Worksheets
bNameIsIn = (InStr(Sheetnames, Wks.name) 0)
If bInGroup Then
If bNameIsIn Then sz = Wks.name
Else
If bNameIsIn Then sz = "" Else sz = Wks.name
End If
If Not sz = "" Then '//build the array
ReDim Preserve Shts(0 To i): Shts(i) = sz: i = i + 1
End If
Next
ActiveWorkbook.Worksheets(Shts).Select
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,514
Default Array

GS formulated on Wednesday :
Next
ActiveWorkbook.Worksheets(Shts).Select
End Sub


Oops! The above should read...
Next
Wkb.Worksheets(Shts).Select
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 420
Default Array

Since you're only copying a single sheet, you don't need the Array() portion:

ThisWorkbook.Worksheets("Tab name").Copy

You could use something like this to get the value from a cell on a worksheet:

ThisWorkbook.Worksheets(thisworkbook.worksheets("S omeSheet").range("A1").Value)).copy

or to save a bit of typing:

With thisworkbook
.worksheets(.worksheets("somesheet").range("a1").v alue).copy
end with



On 06/08/2011 07:10, kevcar40 wrote:
Hi
I am using the formula below to copy a worksheet, which is then pasted out to another workbook.

ThisWorkbook.Worksheets(Array("Tab name")).Copy

is it possible for me to use a cell value instead of having to enter the worksheet name

or

read the Worksheet tab and use this value

thanks

kevin


--
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
Complex conditional summing - array COUNT works, array SUM gives#VALUE fatcatfan Excel Worksheet Functions 4 November 18th 09 06:41 PM
Array formula: how to join 2 ranges together to form one array? Rich_84 Excel Worksheet Functions 2 April 1st 09 06:38 PM
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
combining cells and array from different sheets into an array to pass to IRR() [email protected] Excel Discussion (Misc queries) 3 September 11th 06 07:17 AM


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