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.
|