Minggu, 11 Maret 2012

RE: [ExcelVBA] This Can't Be Happening

 

Glad it was that. At least you have a nice clean solution.

Yes, you should work to remove all dependence on ActiveSheet in your
code.

Best was to do it (in my opinion) is to create a variable holding a
reference to the sheet, and then use that for all references to the
sheet.

Set MySheet = Sheets("Parents2")

then

MySheet.Range("F2").AutoFill ... etc.

You can also use a With construct to reduce the number of times you
actually put "MySheet." in your code. I don't know if this makes the
code run faster, though, and some people prefer the explicit use of the
sheet reference variable throughout the code.

Regards, Dave S

________________________________

From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com] On
Behalf Of Michael Trombetta
Sent: Monday, 12 March 2012 06:56
To: ExcelVBA@yahoogroups.com
Subject: Re: [ExcelVBA] This Can't Be Happening

Hi Dave S and David Grugeon,

My homework: Write 500 (or maybe 5000 times)
I MUST BE SURE WHICH IS THE ACTIVE SHEET
I MUST BE SURE WHICH IS THE ACTIVE SHEET

I MUST BE SURE WHICH IS THE ACTIVE SHEET

I MUST BE SURE WHICH IS THE ACTIVE SHEET

I MUST BE SURE WHICH IS THE ACTIVE SHEET

After I finish that homework, I should write 500 times
THERE IS ALWAYS A N0N-MYSTICAL ANSWER, AND IT'S USUALLY THE WRONG ACTIVE
SHEET.

I added Sheets("Parents2").Activate before the autofill and it works
perfectly. When I was debugging I clicked on Parents2, to see what was
happening, and changed the active sheet. And I did it over and over
again, and never had a clue.

I implemented David Grugeon's suggestion that I combine 2 statements
into 1 with
Range("F2").AutoFill Destination:= etc.

Now I'm thinking I could carry that a step further and add the sheet to
the statement
Sheets("Parents2").Range("F2").AutoFill Destination:= etc
so I could be certain on which sheet the statement will execute.

So thank you both, again, for saving my sanity.
Michael Trombetta

[Non-text portions of this message have been removed]

----------

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]

__._,_.___
Recent Activity:
----------------------------------
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