Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Restricting sheet_selectionchange code to just one column

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
-----------------------------------------------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Restricting sheet_selectionchange code to just one column

If you want to restrict this to Column B add a condition..

If target.Column = 2 Then
'Place your code here
End If

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Restricting sheet_selectionchange code to just one column

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
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
-----------------------------------------------------------

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Restricting sheet_selectionchange code to just one column

Sorry if I didnt put that correctly. Check the performance of code execution
....after removing

Application.EnableEvents = False
Application.ScreenUpdating = False

Can you elaborate your comment "but for two columns because I needed two
columns"


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


"shabutt" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Restricting sheet_selectionchange code to just one column

Thanks Jacob Skaria. After deleting.....

Application.EnableEvents = False
Application.ScreenUpdating = False
Application.EnableEvents = True
Application.ScreenUpdating = True

from my code, scrolling & data entry has become really fast. But I don't
understand why earlier without the "Application.ScreenUpdating = False" in my
code, the flicker wouldn't go and now there is no flicker.

I needed two columns so that rngLast (1, 6) focus remains the same whether I
am in column 10 or 11 because after entering data in cells, I sometimes use
right arrow key. And since I have this code also....

If Target.Column = 10 Then
Selection.AutoFilter field:=10, Criteria1:="="

Thanks again for your generous help.


"Jacob Skaria" wrote:

Sorry if I didnt put that correctly. Check the performance of code execution
...after removing

Application.EnableEvents = False
Application.ScreenUpdating = False

Can you elaborate your comment "but for two columns because I needed two
columns"


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


"shabutt" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting Scroll Prevents Row and Column Choice Colin Hayes Excel Discussion (Misc queries) 3 June 11th 07 12:36 AM
Restricting copied text to one Column Viking Excel Programming 2 June 30th 06 02:28 PM
Restricting Rows Old Music Lover Excel Discussion (Misc queries) 1 July 23rd 05 02:27 AM
Restricting Macros Ed Excel Programming 4 January 17th 05 10:59 PM
Restricting Access to VB Code (xl98) MoonWeazel Excel Programming 3 March 5th 04 02:55 PM


All times are GMT +1. The time now is 03:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"