Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default 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.

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
Need help - Macro to copy a specific range Dileep Chandran Excel Worksheet Functions 0 December 4th 06 10:24 AM
How do i a apply range(autoformat) in non-adjacent cells? Brent from the Bahamas New Users to Excel 2 January 23rd 06 10:42 AM
How to apply rounding across a range of cells with other formulae Steve T Excel Worksheet Functions 1 October 20th 05 07:39 PM
How can I apply the ROUND function to a range of cells in a workbo Ellemarr Excel Discussion (Misc queries) 5 June 11th 05 01:09 AM
How do I modify range of cells viewed in HTML format? Colli Excel Discussion (Misc queries) 0 March 15th 05 02:45 PM


All times are GMT +1. The time now is 12:32 PM.

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

About Us

"It's about Microsoft Excel"