Hello!

I´ve written a code for auto-fill a segment of rows but now i´m having difficulties for the auto-fill to continue in another row. For example, i want to limit the auto-fill from row 12 to row 25. If the data don´t exceed the 14 lines i´m ok. But if exceeds, i want it to continue from row 40. It is possible? Thanks for your help.

The code i already have is this:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim oCell As Excel.Range
Dim oCellResult1 As Excel.Range 'Data
Dim oCellClean1 As Excel.Range 'Data
Dim oRangeID As Excel.Range
Dim iCellCount As Integer

    
If Target.Address = "$T$4" Then

    'sheet with values
    Set oRangeID = Sheets("Registo_EPI").Range("A3:A5000")
    
    
    'sheet range
    Set oCellResult1 = Sheets("Distribuição_EPI").Range("U12") 
   
    'to clean previous data
    Set oCellClean1 = oCellResult1 
    
    While Len(oCellClean1.Value) > 0 

        oCellClean1.ClearContents 'Capacete
        Set oCellClean1 = oCellClean1.Offset(1, 0)
        
    Wend
    

    'data aquisition
    For Each oCell In oRangeID
    
        If oCell.Value = "" Then Exit For

        If oCell.Value = Target.Value Then
            
            
            oCellResult1.Offset(iCellCount, 0).Value = oCell.Offset(0, 6).Value 
          iCellCount = iCellCount + 1
    
         End If

    Next oCell

End If

End Sub