Troublesome Code
First,
Range("b1:b150", "d1:D150")
is the same as:
range("B1:D150")
If you really wanted just rows 1:150 in column B or D, then use:
range("b1:b150,d1:d150")
Private Sub Worksheet_Change(ByVal Target As Range)
dim myRow as long
dim myRng as range
If Target.Cells.Count 1 Then Exit Sub
myrow = target.row -1
If Application.Intersect(Range("b1:d150"), Target) Is Nothing Then
exit sub
end if
set myrng = me.range(.cells(myrow,"D"),.cells(myrow,"X"))
'stop the change from firing this event
application.enableevents = false
myrng.Replace what:="L??O???", _
Replacement:=me.Cells(target.row, "a").Value, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Target.Offset(1, 0).Select
application.enableevents =true
End Sub
(Untested, uncompiled.)
Mark Dullingham wrote:
I have the following code in my work book. It does exactly what I want it to
apart from each time a value is changed and the code runs the code scrolls
back through the entire sheet and as the number of rows is getting quite
extensive now this can take some time.
Does anyone have any idea how to stop this from happening.
Many thanks in advance
Mark Dullingham
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Application.Intersect(Range("b1:b150", "d1:d150"), Target) Is
Nothing Then
Range("D" & ActiveCell.Offset(-1, 0).Row & ":X" & ActiveCell.Offset(-1,
0).Row).Select
Selection.Replace what:="L??O???", _
Replacement:=Cells(ActiveCell.Row, "a").Value, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Target.Offset(1, 0).Select
End If
End Sub
--
Dave Peterson
|