Selected cells become deselected?

B

Bob Holmes

I'm using a worksheet as a front-end for some data entry. I have code in
the 'worksheet_selectionchange' event that enables/disables command buttons
and comboboxes on the sheet based on the column in which the user places the
cursor. I am finding that after selecting some cells for copying, that the
selection goes away as soon as I reach code in this event that is related to
the command button or any object on the worksheet, which means that there is
nothing to paste.
Here is a sample of my code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If blnSaving = True Then Call Check_Existing_Codes(Target)
cmbNewWorkCode.Visible = False
'more code here
End Sub

I select cells, choose to copy the selection and then select the cell where
it should paste. Upon selecting the cell for pasting, this routine is
triggered and the first line causes no problems since it is only checking
the value of a variable. Upon execution of the second line, the selection
disappears and the paste feature is disabled.
I'm certain that this is where I need to place this code, since I need to
know as soon as the user has selected a cell in order to determine where the
cursor is. Is there some way to maintain the selection even though the code
is working on objects on the sheet. Does anyone have any suggestions. I'm
willing to try anything. Thanks for any help you can offer.
 
T

Tom Ogilvy

I think you would have to disable the event to do this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if application.CutCopyMode = True then exit sub
If blnSaving = True Then Call Check_Existing_Codes(Target)
cmbNewWorkCode.Visible = False
'more code here
End Sub
 
B

Bob Holmes

Thanks Tom. That is exactly what I needed.
Every day I learn a lot more about Excel. The most important thing I've
learned is that there is so much more that I don't know about it. Thank God
for people like you helping out those of us who need the help.

--
Bob Holmes

Tom Ogilvy said:
I think you would have to disable the event to do this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if application.CutCopyMode = True then exit sub
If blnSaving = True Then Call Check_Existing_Codes(Target)
cmbNewWorkCode.Visible = False
'more code here
End Sub

--
Regards,
Tom Ogilvy


Bob Holmes said:
I'm using a worksheet as a front-end for some data entry. I have code in
the 'worksheet_selectionchange' event that enables/disables command buttons
and comboboxes on the sheet based on the column in which the user places the
cursor. I am finding that after selecting some cells for copying, that the
selection goes away as soon as I reach code in this event that is
related
to
the command button or any object on the worksheet, which means that
there
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top