![]() |
modify a macro to apply to a specific range of cells
How would I modify the following code to only apply to a range, say A1:A10?
Private Sub Worksheet_Change(ByVal Target As Range) Dim iPos As Long On Error GoTo ws_exit: Application.EnableEvents = False With Target If .Column = 1 Then iPos = InStr(1, Target.Value, " ") If iPos 0 Then .Value = Right(.Value, Len(.Value) - iPos) & _ " " & Left(.Value, iPos - 1) End If End If End With ws_exit: Application.EnableEvents = True End Sub (Code retrieved from: http://groups.google.com/group/micro...701548d16353f8 ) Thanks! Dave -- A hint to posters: Specific, detailed questions are more likely to be answered than questions that provide no detail about your problem. |
modify a macro to apply to a specific range of cells
I presume you mean that you only want it to run if any of those cells are
changed Try this: IF not intersect(target,range("A1:A10")) is nothing then 'put your code here end if "Dave F" wrote: How would I modify the following code to only apply to a range, say A1:A10? Private Sub Worksheet_Change(ByVal Target As Range) Dim iPos As Long On Error GoTo ws_exit: Application.EnableEvents = False With Target If .Column = 1 Then iPos = InStr(1, Target.Value, " ") If iPos 0 Then .Value = Right(.Value, Len(.Value) - iPos) & _ " " & Left(.Value, iPos - 1) End If End If End With ws_exit: Application.EnableEvents = True End Sub (Code retrieved from: http://groups.google.com/group/micro...701548d16353f8 ) Thanks! Dave -- A hint to posters: Specific, detailed questions are more likely to be answered than questions that provide no detail about your problem. |
modify a macro to apply to a specific range of cells
Perfect, thanks.
Dave -- A hint to posters: Specific, detailed questions are more likely to be answered than questions that provide no detail about your problem. "Barb Reinhardt" wrote: I presume you mean that you only want it to run if any of those cells are changed Try this: IF not intersect(target,range("A1:A10")) is nothing then 'put your code here end if "Dave F" wrote: How would I modify the following code to only apply to a range, say A1:A10? Private Sub Worksheet_Change(ByVal Target As Range) Dim iPos As Long On Error GoTo ws_exit: Application.EnableEvents = False With Target If .Column = 1 Then iPos = InStr(1, Target.Value, " ") If iPos 0 Then .Value = Right(.Value, Len(.Value) - iPos) & _ " " & Left(.Value, iPos - 1) End If End If End With ws_exit: Application.EnableEvents = True End Sub (Code retrieved from: http://groups.google.com/group/micro...701548d16353f8 ) Thanks! Dave -- A hint to posters: Specific, detailed questions are more likely to be answered than questions that provide no detail about your problem. |
All times are GMT +1. The time now is 12:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com