View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
shabutt shabutt is offline
external usenet poster
 
Posts: 31
Default Restricting sheet_selectionchange code to just one column

Thank you Jacob Skaria for your help. Here is the modified code as suggested
by you but for two columns because I needed two columns.
-------------------------------------
Option Explicit
Dim rngLast As Range 'last used cell which has lost focus

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.EnableEvents = False
Application.ScreenUpdating = False

If Target.Column 9 And Target.Column < 12 Then

On Error Resume Next

If Not rngLast Is Nothing Then 'check for existence

Me.Shapes("TextBox").TextFrame.Characters.Text = rngLast(1, 6).Value

End If
End If
Set rngLast = Target

Shapes("TextBox").SetShapesDefaultProperties

On Error GoTo 0

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub
-------------------------------------

I don't understand your this comment "Do you really need to use
Application.ScreenUpdating = False in this Change event". Please explain a
little bit.

TIA

"Jacob Skaria" wrote:

Do you really need to use Application.ScreenUpdating = False in this Change
event

If this post helps click Yes
---------------
Jacob Skaria


"shabutt" wrote:

The below event code shows content of a cell which has just lost focus into a
textbox placed in a worksheet. This code works for all cells in the worksheet
but I want the code to restrict to a single column. Another question is
regarding the performance of code execution. How can I speed it up?

Your help is urgently need.
TIA

'A keen beginner in VBA'

-----------------------------------------------------------
Option Explicit
Dim rngLast As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.ScreenUpdating = False
On Error Resume Next
If Not rngLast Is Nothing Then

Me.Shapes("TextBox").TextFrame.Characters.Text = rngLast(1, 6).Value

End If

Set rngLast = Target

Shapes("TextBox").SetShapesDefaultProperties
On Error GoTo 0
Application.ScreenUpdating = True

End Sub
-----------------------------------------------------------