Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2006, 07:51 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to avoid printing "1" after Sendkeys

Hi,
I have an Excel2003 VBA program that selects and displays columns from another sheet which contains the whole database. The following code snippet sums the selected columns, but always leaves a 1 in the last selected cell. Is there a way to avoid this?
'sum columns F,K, L
'Define the range
Set rng = Range("F2:F" & r)

'Go to cell that should contain the sum
Sheet4.Cells(r + 2, 6).Select

'Calculate the sum & make addresses not absolute so can copy for each column
ActiveCell.Formula = "=SUM(" & rng.Address(RowAbsolute:=False, ColumnAbsolute:=False) & ")"

'Use copy method
ActiveCell.Copy
Sheet4.Cells(r + 2, 9).Select
Sheet4.Paste
Sheet4.Cells(r + 2, 11).Select
Sheet4.Paste
Sheet4.Cells(r + 2, 12).Select
Sheet4.Paste
Sheet4.Cells(r + 3, 13).Select 'unused cell

'Get rid of active copy activity
Application.SendKeys (xlEscKey)

'Rename the sheet tab
Sheet4.Name = ComboBox3.Text
'Autofit columns
Sheet4.Columns("A:M").AutoFit

The reason for the sendkeys line is to turn off the annoying activity around the original "copy from" cell. Otherwise the user must hit the "Esc" key. But now a "1" appears in the last selected cell. Any ideas? I know I can do the sums by "brute force" with loops, but think there is probably a way to get around the "1" problem.
Thanks,
Font.
 
Old August 18th, 2006, 03:07 PM
Authorized User
 
Join Date: Jul 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Change Application.SendKeys (xlEscKey) on Application.CutCopyMode = False


 
Old August 18th, 2006, 05:21 PM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much. It worked great!:)
You saved me a lot of searching.
Font.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Sendkeys Add-In Problem tiabooks Excel VBA 0 November 6th, 2006 01:31 PM
SendKeys wassa Access VBA 1 July 16th, 2006 02:55 AM
Please Help! - SendKeys wassa Access VBA 1 June 9th, 2006 07:41 AM
how to avoid printing out notice hanson Beginning PHP 1 August 6th, 2004 06:54 AM
SendKeys.Send LCTRL ? ItshiBan VS.NET 2002/2003 0 September 4th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.