modify a macro to apply to a specific range of cells

G

Guest

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/micr...f064482e88d/a5701548d16353f8#a5701548d16353f8 )

Thanks!

Dave
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top