SendKeys Question

I have inherited a worksheet that has some macros that were coded in Excel 2003 and uses the line

SendKeys "+{TAB}", -1

I am using Excel 2010 now and the code is malfunctioning and I belive it has to do with that line. I belive the +Tab is to shift to the next cell to the left but I do not know what the -1 is for. I have tried searching for what the -1 is supposed to do but cannot find it. Can anyone tell me what it is for? Thanks!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The syntax of Sendkeys is

Sendkeys String,Wait

From Excel's Help

Sends one or more keystrokes to the active window as if typed at the keyboard.


SendKeys string[, wait]

The SendKeys statement syntax has these named arguments:

Part Description
string Required. String expression specifying the keystrokes to send.
Wait Optional. Boolean value specifying the wait mode. If False (default), control is returned to the procedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.

MistbornAuthor Commented:
Thanks for he reply but I am still confused. It says that the -1 should be setting a wait mode...but what is the wait mode that the -1 sets it to?
It has to be 0 or 1 and not -1

or best to use True/False

Change the code to

SendKeys "+{TAB}", True

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Rory ArchibaldCommented:
Even better, don't use sendkeys if possible as it is not that reliable. If it is just being used to select another cell, it's unnecessary anyway, but can you post the code so we can see exactly what it's doing?
MistbornAuthor Commented:

Thanks for your help, I just figured out what was wrong! The shift+tab was not working beacuse some of the cells needed to be locked and had gotten unlocked causing it to not skip over cells that it needed to. The -1 must just default to a false and had nothing to do with the actual problem but it had me on the right track. Thanks again for the assistance.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You are welcome :)

MistbornAuthor Commented:
Copying the help file didn't really help at all.

It appears that you resolved the problem yourself, albeit with some help from the Experts, and so while your comment will be marked with the answer Sid and rorya will share in the points.

In any event, the original C grade was wholly unwarranted; it should typically be reserved for cases where the Expert(s) gave vague and incomplete answers and then failed to reply to reasonable requests for clarification.

FWIW, I know a thing ir two about Excel, and rorya's advice to avoid SendKeys is best practice.  Also, -1 does NOT convert to False in VBA.  -1 is boolean True, 0 is boolean False, and in a type conversion any non-zero numeric value converts to the True.
EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.