View Full Version : [SOLVED:] Do something when specific cell selected
excelliot
08-11-2005, 10:34 PM
Hi can i have code fordoing something when specific cell selected?
Ken Puls
08-11-2005, 10:36 PM
Hi there,
Something like this?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$4" Then
MsgBox "Cell A4 has just been selected!"
End If
End Sub
Must be placed in the code module for the worksheet you want it to work on.
excelliot
08-11-2005, 10:54 PM
Yes like that only thanks
Ken Puls
08-11-2005, 10:59 PM
You're welcome! :)
excelliot
08-11-2005, 11:18 PM
One problem in thuis code
I'm unnble to perform cut & paste
mdmackillop
08-12-2005, 12:32 AM
This works for me.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$4" Then
DoMove
End If
End Sub
Sub DoMove()
Application.EnableEvents = False
Range("C4:C7").Cut
Range("E4").Select
ActiveSheet.Paste
Application.EnableEvents = True
End Sub
excelliot
08-12-2005, 02:10 AM
see this file containing macro
i am not able to perform cut(ctrl+x) & paste (ctrl+v) option after having this macro
mdmackillop
08-12-2005, 05:15 AM
You have some logic problems here
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$2" Then
Application.MoveAfterReturnDirection = xlToLeft
Else
Application.MoveAfterReturnDirection = xlDown
End If
End Sub
Moving into cell A2 does change the direction to left, but you cannot go left. Clicking in any other cell returns the move direction to down.
Regarding the cut and paste, you do not show this bit of your code, but you need the Events disabled to prevent the worksheet change event ocurring when you select the cell where the code is to be pasted.
excelliot
08-15-2005, 03:13 AM
I think u r not getting me
after using above code general cut & paste function is not working
see file submitted by me for detail
mdmackillop
08-15-2005, 10:15 AM
:banghead: I see now! Sorry, I've no idea why this is happening, but maybe someone else can help.
For some reason it seems the cut/copied value is being lost from the clipboard when the Application line runs. I've tried Application.Calculate as well and the same problem occurs.
mdmackillop
08-16-2005, 04:36 AM
I reposted your question here, for more assistance.
http://www.vbaexpress.com/forum/showthread.php?t=4650
It just seems to be the way the system works that is causing your problem
Regards
Malcolm
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.