View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Loosing Cell Selection

In 99% of the cases you don't have to move, select, activate anything at all, leaving your
current location intact and your operations invisible.

Run this in a 3-or-more sheet empty workbook, Sheet1 active, some cell selected:

Sub test()
Sheets(2).Range("C3:D6").Interior.ColorIndex = 3
Sheets(3).Range("C12").Value = "Kilroy was here"
Sheets(3).Range("C12").Interior.ColorIndex = 19
Sheets(3).Range("C12").Copy Sheets(2).Range("A1")
Sheets(2).Range("A2").Value = "You ran me from " & _
ActiveSheet.Name & "!" & Selection.Address
End Sub

All changes are in sheets 2 and 3.
--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Nick" wrote in message
...
In excel, I selected a cell or range of cells to copy, and
they highlighted, I have code that runs on OnKey event.
This code changes the color of a few cells.
Because of the coding for coloring the selection of cells
for copy are lost. Is there a way to preserve the original
cells from loosing focus and selection?