Dear Paul Edstein, I am grateful for your kindness and your help, before you submit your last code (which is a master piece and works well, all though I need some time to digest it, and my be convert it into a function) I reached the following function using your previous cods:
Function mainp(h, v, f, l)
Dim i As Integer
'h = 1 ' (h=1 Down) (h=-1 UP) (h=0 no move)
'v = 1 ' (v=1 Right) (v=-1 Left) (v=0 no move)
'f = replacement value
'l= max loop value
With ActiveCell
If .value = f Then
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For i = 1 To l
If .Offset(i * h, i * v).value > 0 Then ' Positive
.Offset(i * h, i * v).value = 1.1 ' Replacement value
Exit For
ElseIf .Offset(i * h, i * v).value < 0 Then 'Exit loop if negative
Exit For
End If
Next
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End With
End Function
The reason why I used a function is to be more flexible in using different versions of searching replacing direction: up, down, from up to left, from down to right ….etc.
Sub hrm() 'this loops the whole range r10:y17 cell by cell
Dim col As Integer
Dim row As Integer
Sheets("hrm").Select ' the name of the sheet=the name of the macro
refill
For row = 10 To 18
For col = 18 To 26
Cells(row, col).Select
'Call mainp(1, 1, -5, 7) '(h=1 Down)(v=1 Right)
' Call mainp(-1, -1, -5, 7) '(h=-1 UP) (v=-1 Left)
' Call mainp(1, -1, -5, 7) ' (h=1 Down) (v=-1 Left)
' Call mainp(-1, 1, -5, 7) ' (h=-1 UP) (v=1 Right)
Call mainp(1, 0, -5, 7) '(h=1 Down)
Call mainp(-1, o, -5, 7) ' (h=-1 UP)
Call mainp(0, 1, -5, 7) '(v=1 Right)
Call mainp(0, -1, -5, 7) '(v=-1 Left)
Next col
Next row
End Sub
The above code is slandered, it contains all directions, for example if I want down, right, up, left (horizontal & vertical) I just insert (') before the diagonal parts to disable it …etc
Thanks a lot.