PC Review


Reply
 
 
kevcar40
Guest
Posts: n/a
 
      8th Jun 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

 
Reply With Quote
 
 
 
 
GS
Guest
Posts: n/a
 
      8th Jun 2011
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


 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      8th Jun 2011
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


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Jun 2011
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("SomeSheet").range("A1").Value)).copy

or to save a bit of typing:

With thisworkbook
.worksheets(.worksheets("somesheet").range("a1").value).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 With Quote
 
 
 
Reply

« Re: Array | JustNN »
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent cell/array references from changing when altering/moving thecell/array nme Microsoft Excel Misc 1 19th Sep 2008 01:53 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
Pass from C# (framework 1.1) array of delegates to unmanaged DLL as array of function pointers verpeter@gmail.com Microsoft C# .NET 0 23rd Aug 2006 02:20 PM
select variables ranges, copy to array, paste the array in new workbook Mathew Microsoft Excel Worksheet Functions 1 1st Apr 2005 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.