PC Review


Reply
Thread Tools Rate Thread

Changing a macro from a specific worksheet to any worksheet

 
 
=?Utf-8?B?TWFuZHJha2VETQ==?=
Guest
Posts: n/a
 
      3rd Nov 2007
Hi,

I'm creating a series of macros that will access a sheet, copy a header line
and then return to the original worksheet and paste the give header where I
want it to go. I don't have any real problem creating the macro itself.
Where my problem is, is that right now, it's only good for one sheet. The
way the macro reads, it copies the headers and then comes back to the
worksheet that I was on when I originally created the macro. So then, how do
I change the macro from returning to the original sheet and return to the
sheet that I am currently on? Any help would be appreciated.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      3rd Nov 2007
Hi MandrakeDM -

Sub mandrake()
Worksheets("HeaderSheet").Range("A1:J1").Copy
ActiveSheet.Paste Destination:=Range("B12")
End Sub
------

I also suggest adding the following optional statement just prior to the End
Sub to turn off the flashing copy marquee on the copied header source range:

Application.CutCopyMode = False
End Sub

--
Jay


"MandrakeDM" wrote:

> Hi,
>
> I'm creating a series of macros that will access a sheet, copy a header line
> and then return to the original worksheet and paste the give header where I
> want it to go. I don't have any real problem creating the macro itself.
> Where my problem is, is that right now, it's only good for one sheet. The
> way the macro reads, it copies the headers and then comes back to the
> worksheet that I was on when I originally created the macro. So then, how do
> I change the macro from returning to the original sheet and return to the
> sheet that I am currently on? Any help would be appreciated.

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      3rd Nov 2007
The first macro goes to Sheet3 to copy and then returns to Sheet1 to paste:

Sub Macro1()
Sheets("Sheet3").Select
Range("G4:H9").Select
Range("G9").Activate
Selection.Copy
Sheets("Sheet1").Select
Range("C9").Select
ActiveSheet.Paste
End Sub

The next macro "remembers" where it came from and returns there:

Sub generall()
Dim s As String
s = ActiveSheet.Name
Sheets("Sheet3").Select
Range("G4:H9").Select
Range("G9").Activate
Selection.Copy
Sheets(s).Select
Range("C9").Select
ActiveSheet.Paste
End Sub

Actually it is not necessary to jump back and forth at all.
--
Gary''s Student - gsnu200753


"MandrakeDM" wrote:

> Hi,
>
> I'm creating a series of macros that will access a sheet, copy a header line
> and then return to the original worksheet and paste the give header where I
> want it to go. I don't have any real problem creating the macro itself.
> Where my problem is, is that right now, it's only good for one sheet. The
> way the macro reads, it copies the headers and then comes back to the
> worksheet that I was on when I originally created the macro. So then, how do
> I change the macro from returning to the original sheet and return to the
> sheet that I am currently on? Any help would be appreciated.

 
Reply With Quote
 
=?Utf-8?B?TWFuZHJha2VETQ==?=
Guest
Posts: n/a
 
      3rd Nov 2007
Thanks Jay. I won't be able to try it until Sunday night but it looks good.
Between you and Gary's Student, I think it's solved.

Mandrake

"Jay" wrote:

> Hi MandrakeDM -
>
> Sub mandrake()
> Worksheets("HeaderSheet").Range("A1:J1").Copy
> ActiveSheet.Paste Destination:=Range("B12")
> End Sub
> ------
>
> I also suggest adding the following optional statement just prior to the End
> Sub to turn off the flashing copy marquee on the copied header source range:
>
> Application.CutCopyMode = False
> End Sub
>
> --
> Jay
>
>
> "MandrakeDM" wrote:
>
> > Hi,
> >
> > I'm creating a series of macros that will access a sheet, copy a header line
> > and then return to the original worksheet and paste the give header where I
> > want it to go. I don't have any real problem creating the macro itself.
> > Where my problem is, is that right now, it's only good for one sheet. The
> > way the macro reads, it copies the headers and then comes back to the
> > worksheet that I was on when I originally created the macro. So then, how do
> > I change the macro from returning to the original sheet and return to the
> > sheet that I am currently on? Any help would be appreciated.

 
Reply With Quote
 
=?Utf-8?B?TWFuZHJha2VETQ==?=
Guest
Posts: n/a
 
      3rd Nov 2007
Thanks so much for the help. I'll try it out on Sunday night. Between you and
Jay, I think the problems fixed.

Mandrake

"Gary''s Student" wrote:

> The first macro goes to Sheet3 to copy and then returns to Sheet1 to paste:
>
> Sub Macro1()
> Sheets("Sheet3").Select
> Range("G4:H9").Select
> Range("G9").Activate
> Selection.Copy
> Sheets("Sheet1").Select
> Range("C9").Select
> ActiveSheet.Paste
> End Sub
>
> The next macro "remembers" where it came from and returns there:
>
> Sub generall()
> Dim s As String
> s = ActiveSheet.Name
> Sheets("Sheet3").Select
> Range("G4:H9").Select
> Range("G9").Activate
> Selection.Copy
> Sheets(s).Select
> Range("C9").Select
> ActiveSheet.Paste
> End Sub
>
> Actually it is not necessary to jump back and forth at all.
> --
> Gary''s Student - gsnu200753
>
>
> "MandrakeDM" wrote:
>
> > Hi,
> >
> > I'm creating a series of macros that will access a sheet, copy a header line
> > and then return to the original worksheet and paste the give header where I
> > want it to go. I don't have any real problem creating the macro itself.
> > Where my problem is, is that right now, it's only good for one sheet. The
> > way the macro reads, it copies the headers and then comes back to the
> > worksheet that I was on when I originally created the macro. So then, how do
> > I change the macro from returning to the original sheet and return to the
> > sheet that I am currently on? Any help would be appreciated.

 
Reply With Quote
 
 
 
Reply

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
How do I get a macro to be non worksheet specific? navel151 Microsoft Excel Worksheet Functions 6 4th Jan 2010 09:46 PM
Force macro to run on a specific worksheet Don Microsoft Excel Discussion 2 6th Jun 2009 04:45 PM
How to run specific macro on selected worksheet? Harshad Microsoft Excel Misc 2 31st Oct 2008 06:56 AM
make a macro 'worksheet specific' =?Utf-8?B?TG9yaQ==?= Microsoft Excel Misc 11 29th Oct 2007 12:38 AM
Help with a macro to open to a specific worksheet =?Utf-8?B?RUFIUkVOUw==?= Microsoft Excel Worksheet Functions 0 30th Nov 2005 08:36 PM


Features
 

Advertising
 

Newsgroups
 


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