How to return to current worksheet in a macro

C

CWatters

I'm trying to make a macro that copies a few lines from worksheet1 into the
current worksheet2. The problem is that the name of worksheet2 can change so
I can't use

Windows("worksheet2").Activate

to return the focus before doing a paste.

How do I do this please?
 
F

Frank Kabel

Hi
normally no need at all for select / activate.

use something like
worksheets("sheet2").range("A1:A100").copy _
destination:=worksheets("sheet1").range("A1:A100")
 
C

CWatters

Thanks frank I'll give it a try.

Colin


Frank Kabel said:
Hi
normally no need at all for select / activate.

use something like
worksheets("sheet2").range("A1:A100").copy _
destination:=worksheets("sheet1").range("A1:A100")
 
C

CWatters

Sorry i think I need a bit more help... What I'm actually trying to do is
write a macro to copy an image from one workbook/sheet to a cell on the
cutrrent workbook/sheet

How do I select the image on the source workbook/sheet?

Is there something like...

[workbook1]worksheet!.image.copy destination=activecell

I'm trying to run before I can walk!

Colin
 
F

Frank Kabel

Hi
what do you mean with 'image of the worksheet'?

--
Regards
Frank Kabel
Frankfurt, Germany

CWatters said:
Sorry i think I need a bit more help... What I'm actually trying to do is
write a macro to copy an image from one workbook/sheet to a cell on the
cutrrent workbook/sheet

How do I select the image on the source workbook/sheet?

Is there something like...

[workbook1]worksheet!.image.copy destination=activecell

I'm trying to run before I can walk!

Colin










CWatters said:
Thanks frank I'll give it a try.

Colin
 
C

CWatters

Hi Frank,

I think my problem is simpler than you imagine...

I have [workbook1]worksheet1 that has a picture on it. What I'm trying to do
is copy that picture to [workbook2]worksheet2.

If I was doing this manually I would simply select the picture on the source
worksheet and go edit->copy. Then select the cell where I wanted the picture
to go on the destination worksheet and again Edit-> Paste.

The problem is how to do this in a macro? I think it's something like
this....

Dim Pic As Picture
Pic = [WorkBook1].WorkSheet1!Pictures("Picture 1").copy
ActiveSheet.Pictures.Insert(Pic).Select

But line 2 gives me an error about "needing an object"

Colin

Frank Kabel said:
Hi
what do you mean with 'image of the worksheet'?

--
Regards
Frank Kabel
Frankfurt, Germany

CWatters said:
Sorry i think I need a bit more help... What I'm actually trying to do is
write a macro to copy an image from one workbook/sheet to a cell on the
cutrrent workbook/sheet

How do I select the image on the source workbook/sheet?

Is there something like...

[workbook1]worksheet!.image.copy destination=activecell

I'm trying to run before I can walk!

Colin










CWatters said:
Thanks frank I'll give it a try.

Colin


Hi
normally no need at all for select / activate.

use something like
worksheets("sheet2").range("A1:A100").copy _
destination:=worksheets("sheet1").range("A1:A100")



--
Regards
Frank Kabel
Frankfurt, Germany

I'm trying to make a macro that copies a few lines from worksheet1
into the
current worksheet2. The problem is that the name of worksheet2 can
change so
I can't use

Windows("worksheet2").Activate

to return the focus before doing a paste.

How do I do this please?
 
D

Dave Peterson

I recorded a macro when I did it manually:

Option Explicit
Sub Macro1()
ActiveSheet.Shapes("Picture 1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("D11").Select
ActiveSheet.Paste
End Sub

One way change it slightly:

Option Explicit
Sub testme01()

Dim myPic As Picture
Dim toCell As Range

Set myPic = Worksheets("sheet1").Pictures("Picture 1")
Set toCell = Worksheets("sheet2").Range("d22")

myPic.Copy
Application.Goto toCell
toCell.Parent.Paste

End Sub

Hi Frank,

I think my problem is simpler than you imagine...

I have [workbook1]worksheet1 that has a picture on it. What I'm trying to do
is copy that picture to [workbook2]worksheet2.

If I was doing this manually I would simply select the picture on the source
worksheet and go edit->copy. Then select the cell where I wanted the picture
to go on the destination worksheet and again Edit-> Paste.

The problem is how to do this in a macro? I think it's something like
this....

Dim Pic As Picture
Pic = [WorkBook1].WorkSheet1!Pictures("Picture 1").copy
ActiveSheet.Pictures.Insert(Pic).Select

But line 2 gives me an error about "needing an object"

Colin

Frank Kabel said:
Hi
what do you mean with 'image of the worksheet'?

--
Regards
Frank Kabel
Frankfurt, Germany

CWatters said:
Sorry i think I need a bit more help... What I'm actually trying to do is
write a macro to copy an image from one workbook/sheet to a cell on the
cutrrent workbook/sheet

How do I select the image on the source workbook/sheet?

Is there something like...

[workbook1]worksheet!.image.copy destination=activecell

I'm trying to run before I can walk!

Colin










Thanks frank I'll give it a try.

Colin


Hi
normally no need at all for select / activate.

use something like
worksheets("sheet2").range("A1:A100").copy _
destination:=worksheets("sheet1").range("A1:A100")



--
Regards
Frank Kabel
Frankfurt, Germany

I'm trying to make a macro that copies a few lines from worksheet1
into the
current worksheet2. The problem is that the name of worksheet2 can
change so
I can't use

Windows("worksheet2").Activate

to return the focus before doing a paste.

How do I do this please?
 
C

CWatters

Hi Dave,

That's it. Many thanks.

Colin





Dave Peterson said:
I recorded a macro when I did it manually:

Option Explicit
Sub Macro1()
ActiveSheet.Shapes("Picture 1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("D11").Select
ActiveSheet.Paste
End Sub

One way change it slightly:

Option Explicit
Sub testme01()

Dim myPic As Picture
Dim toCell As Range

Set myPic = Worksheets("sheet1").Pictures("Picture 1")
Set toCell = Worksheets("sheet2").Range("d22")

myPic.Copy
Application.Goto toCell
toCell.Parent.Paste

End Sub

Hi Frank,

I think my problem is simpler than you imagine...

I have [workbook1]worksheet1 that has a picture on it. What I'm trying to do
is copy that picture to [workbook2]worksheet2.

If I was doing this manually I would simply select the picture on the source
worksheet and go edit->copy. Then select the cell where I wanted the picture
to go on the destination worksheet and again Edit-> Paste.

The problem is how to do this in a macro? I think it's something like
this....

Dim Pic As Picture
Pic = [WorkBook1].WorkSheet1!Pictures("Picture 1").copy
ActiveSheet.Pictures.Insert(Pic).Select

But line 2 gives me an error about "needing an object"

Colin

Frank Kabel said:
Hi
what do you mean with 'image of the worksheet'?

--
Regards
Frank Kabel
Frankfurt, Germany

Sorry i think I need a bit more help... What I'm actually trying to
do is
write a macro to copy an image from one workbook/sheet to a cell on
the
cutrrent workbook/sheet

How do I select the image on the source workbook/sheet?

Is there something like...

[workbook1]worksheet!.image.copy destination=activecell

I'm trying to run before I can walk!

Colin










Thanks frank I'll give it a try.

Colin


Hi
normally no need at all for select / activate.

use something like
worksheets("sheet2").range("A1:A100").copy _
destination:=worksheets("sheet1").range("A1:A100")



--
Regards
Frank Kabel
Frankfurt, Germany

I'm trying to make a macro that copies a few lines from
worksheet1
into the
current worksheet2. The problem is that the name of worksheet2
can
change so
I can't use

Windows("worksheet2").Activate

to return the focus before doing a paste.

How do I do this please?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top