Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro Active Page Name

I have an excel macro the when a cell is triggered it creates and names a new
worksheet. what I want to do is in that worksheet run a macro that copies all
from "VAT Invoice" into the active sheet.

What i've recorded is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
Sheets("989989").Select
ActiveSheet.Paste

Sheet "980089" is the issue, as it will never be the same. The sheet name is
created from Cell B4 in "VAT Invoice"

How can I tell the macro to find the active worksheet name and then put the
data there.

Thanks for your help

John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Macro Active Page Name

Try this:
Sheets(Sheets("VAT Invoice").Range("B4")).Select

Regards,
Stefi

€žBuzz€ť ezt Ă*rta:

I have an excel macro the when a cell is triggered it creates and names a new
worksheet. what I want to do is in that worksheet run a macro that copies all
from "VAT Invoice" into the active sheet.

What i've recorded is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
Sheets("989989").Select
ActiveSheet.Paste

Sheet "980089" is the issue, as it will never be the same. The sheet name is
created from Cell B4 in "VAT Invoice"

How can I tell the macro to find the active worksheet name and then put the
data there.

Thanks for your help

John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Macro Active Page Name

capture the value of the cell and assign it to a variable. Then use the
variable name to describe the workshet you want to activate:

nextsht=activecell.value
worksheets(nextsht).select


"Buzz" wrote:

I have an excel macro the when a cell is triggered it creates and names a new
worksheet. what I want to do is in that worksheet run a macro that copies all
from "VAT Invoice" into the active sheet.

What i've recorded is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
Sheets("989989").Select
ActiveSheet.Paste

Sheet "980089" is the issue, as it will never be the same. The sheet name is
created from Cell B4 in "VAT Invoice"

How can I tell the macro to find the active worksheet name and then put the
data there.

Thanks for your help

John


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro Active Page Name

Thanks for the replies.

I've tried them both but they both debug on the Select line for the new
worksheet. This is something dont get involved in so be gentle. what i've
tried is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
ActiveCellValue = Sheets("VAT Invoice").Range("B4").Select
nextsht = ActiveCell.Value
Sheets(ActiveCell.Value).Select
'Sheets(Sheets("VATInvoice").Range("B4")).Select
'Sheets("nextsht").Select
'ActiveSheet.Paste

The nextsht and activecell values are the correct value when i highlight the
VB code.

Any ideas?

John

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Macro Active Page Name

Try this

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Selection.Copy
nextsht = Sheets("VAT Invoice").Range("B4").value
worksheets(nextsht).avctivate
ActiveSheet.Paste

"Buzz" wrote:

Thanks for the replies.

I've tried them both but they both debug on the Select line for the new
worksheet. This is something dont get involved in so be gentle. what i've
tried is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
ActiveCellValue = Sheets("VAT Invoice").Range("B4").Select
nextsht = ActiveCell.Value
Sheets(ActiveCell.Value).Select
'Sheets(Sheets("VATInvoice").Range("B4")).Select
'Sheets("nextsht").Select
'ActiveSheet.Paste

The nextsht and activecell values are the correct value when i highlight the
VB code.

Any ideas?

John



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro Active Page Name

I think you'll find things much easier and more clear if you get rid
of all your Select and Activate statements. It is (almost) never
necessary to Select anything. Instead, declare variables for the
worksheets and the range. For example,


Sub AAA()

Dim VATSheet As Worksheet
Dim DestSheet As Worksheet
Dim Dest As Range

Set VATSheet = Worksheets("VAT Invoice")
Set DestSheet = Worksheets(VATSheet.Range("B4").Value)
Set Dest = DestSheet.Range("A1") '<<< Destination of copy
VATSheet.Range("A1:J37").Copy Destination:=Dest

End Sub

Here, VATSheet gets set to the "VAT Invoice" worksheet. DestSheet
gets set to the worksheet named in cell B4 of the VATSheet. Dest, the
destination of the Copy operation, gets set to A1 of DestSheet.
Finally, the code copies A1:J37 to the location of Dest.

No Activates, Selects, or Pastes are required. Moreover, the code
will work regardless of which worksheet is active, which makes the
code more robust and flexible.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Thu, 19 Feb 2009 05:14:01 -0800, Buzz
wrote:

I have an excel macro the when a cell is triggered it creates and names a new
worksheet. what I want to do is in that worksheet run a macro that copies all
from "VAT Invoice" into the active sheet.

What i've recorded is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
Sheets("989989").Select
ActiveSheet.Paste

Sheet "980089" is the issue, as it will never be the same. The sheet name is
created from Cell B4 in "VAT Invoice"

How can I tell the macro to find the active worksheet name and then put the
data there.

Thanks for your help

John

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro Active Page Name

Thinking further, you entire code can be reduced to a single line of
code:


Worksheets("VAT Invoice").Range("A1:J37").Copy _
Destination:=Worksheets(Worksheets("VAT Invoice") _
.Range("B4").Text).Range("A1")

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 19 Feb 2009 09:32:54 -0600, Chip Pearson
wrote:

I think you'll find things much easier and more clear if you get rid
of all your Select and Activate statements. It is (almost) never
necessary to Select anything. Instead, declare variables for the
worksheets and the range. For example,


Sub AAA()

Dim VATSheet As Worksheet
Dim DestSheet As Worksheet
Dim Dest As Range

Set VATSheet = Worksheets("VAT Invoice")
Set DestSheet = Worksheets(VATSheet.Range("B4").Value)
Set Dest = DestSheet.Range("A1") '<<< Destination of copy
VATSheet.Range("A1:J37").Copy Destination:=Dest

End Sub

Here, VATSheet gets set to the "VAT Invoice" worksheet. DestSheet
gets set to the worksheet named in cell B4 of the VATSheet. Dest, the
destination of the Copy operation, gets set to A1 of DestSheet.
Finally, the code copies A1:J37 to the location of Dest.

No Activates, Selects, or Pastes are required. Moreover, the code
will work regardless of which worksheet is active, which makes the
code more robust and flexible.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Thu, 19 Feb 2009 05:14:01 -0800, Buzz
wrote:

I have an excel macro the when a cell is triggered it creates and names a new
worksheet. what I want to do is in that worksheet run a macro that copies all
from "VAT Invoice" into the active sheet.

What i've recorded is

Sheets("VAT Invoice").Select
Range("A1:J37").Select
Range("J37").Activate
Selection.Copy
Sheets("989989").Select
ActiveSheet.Paste

Sheet "980089" is the issue, as it will never be the same. The sheet name is
created from Cell B4 in "VAT Invoice"

How can I tell the macro to find the active worksheet name and then put the
data there.

Thanks for your help

John

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro Active Page Name

Excellent Thanks Chip!

John




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
run macro although blinking cursor is active in an active cell bartman1980 Excel Programming 1 December 20th 07 11:29 AM
sending active sheet by mail without macro (from Ron's page) Dan Excel Programming 5 November 8th 07 05:40 PM
Button to print non-active page - How? Bafa[_9_] Excel Programming 4 August 21st 06 04:53 AM
which page is active JT Excel Programming 4 October 25th 05 03:56 PM
Make excel the active page kaiser Excel Programming 2 October 8th 05 04:48 AM


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