Sorry, can't type. I'll redo my second and third paras:
The copy works in Sheet1 without a select of that sheet, because it is a
copy, not a select.
The select of the Sheet2 cell without a select of Sheet2 first fails
because you can't select something on a sheet where the sheet itself is
not selected.
Hope this bit about the select of cells without a select of sheet now
reads correctly. Essentially, it's only actions that change the active
cell (e.g. the Select of a cell on Sheet2) that can't be done if the
sheet itself is not selected. "Normal" statements that act on cells
directly from VBA statements don't require their sheets to be selected.
Regards, Dave S
________________________________
From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com] On
Behalf Of David Smart
Sent: Friday, 13 January 2012 08:29
To: ExcelVBA@yahoogroups.com
Subject: Re: [ExcelVBA] Annother Puzzle
You are correct. Range has PasteSpecial but no Paste, for some unknown
reason. Glad I said "not tested" in my reply. :-)
The copy works in Sheet1 without a select of that sheet, because it is a
copy, not a select.
The select of the Sheet2 cell without a select of Sheet1 first fails
because
you can't select something on a sheet where the sheet itself is not
selected.
You could put the select of Sheet2 back into the code.
Alternatively, you can use PasteSpecial in the way you have, which I
think
is a better approach.
Thirdly, there is a variant of the Copy, which supplies a destination
...
Sheets("Sheet1").Range("A3:C3").Copy
(Destination:=Sheets("Sheet2").Range("A7"))
... note that Destination has a colon and an equals after it because it
is a
named parameter ...
again, not tested, but this will hopefully :-) work OK.
Regards, Dave S
----- Original Message -----
From: "Michael Trombetta" <mickey11030@yahoo.com
<mailto:mickey11030%40yahoo.com> >
To: <ExcelVBA@yahoogroups.com <mailto:ExcelVBA%40yahoogroups.com> >
Sent: Friday, January 13, 2012 3:27 AM
Subject: RE: [ExcelVBA] Annother Puzzle
Thank you David for your suggestion, although I don't understand it. You
say
the problem is a lack of select of Sheet2, but the first statement works
without a select for Sheet1. Nevertheless I implemented your suggestion
of
collapsed the last 2 statements into
Sheets("Sheet2").Range("A7").Paste
and believe it or not that fails with the error message: Object doesn't
support this property or method.
I used the Object Browser (of which I understand about 2%) and it seems
to
say that the Range object does NOT have a Paste method! It does have a
PasteSpecial method. So I recorded a macro using PasteSpecial (to get
the
format) and changed the last statement to
Sheets("Sheet2").Range("A7").PasteSpecial Paste:=xlPasteAll,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
and that works even when Sheet3 is active when the subroutine is run.
Why Microsoft decided that the Range object should not have a Paste
method
but should have a PasteSpecial method is a question for another day.
Thanks again.
Mickey
[Non-text portions of this message have been removed]
------------------------------------
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles!
Go
here: http://www.mousetrax.com/techtrax to enter the ezine, then search
the
ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------Yahoo! Groups Links
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1416 / Virus Database: 2109/4137 - Release Date: 01/11/12
----------
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mails are not encrypted and cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities
or related financial instruments.
UBS reserves the right to retain all messages. Messages are protected
and accessed only in legally justified cases.
[Non-text portions of this message have been removed]
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar