code not working with auto fill

  • Thread starter Thread starter forcast
  • Start date Start date
F

forcast

I have a code working very well when I fill cells manually, but when I use
auto fill the code stops working as if it does not exist . how can I make
the code work with the auto fill.
Thank you.
 
Don't really understand the question. Do you mean that you are recording code
but the recorded code does not work with Autofill?
 
Dear OssieMac
Thank you for replying my problem is :
This the code
If Target.Column = 3 Then
If Selection.Count > 1 Then Exit Sub
Target.Offset(0, -1).Formula = "=Row()-1"
If Target = "" Then Target.Offset(0, -1) = ""
End If
End Sub
Now if you fill C1, C2 manually with number 1 ,2 you can see the result on
B1,B2 it is 0,1 now everything is OK so far but if you auto fill
C3,C4,C5……..you can not see any result on B3,B4,B5……….also if you make C7 =
F4 and you fill F4 with any number say 10 you can see your number 10
automatically on C7 but no result on B7 which mean the code is not respond .
Thank you
forcast
 
Maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRng As Range
Dim myCell As Range

Set myRng = Intersect(Target, Me.Range("C:C"))

If myRng Is Nothing Then
Exit Sub
End If

For Each myCell In myRng.Cells
If myCell.Value = "" Then
myCell.Offset(0, -1).Value = ""
Else
myCell.Offset(0, -1).Formula = "=Row()-1"
End If
Next myCell
End Sub
 
Back
Top