I want to run the code that will clear the rows in specific ranges of my sheet. I have also the condition which rows' content should be cleared i.e. if the ID in the first column of my range matches the defined name with the first characters (i.e. if the ID in the column has more characters than a defined name but it matches with the first characters - the row content should be erased )
I would like to that for a few ranges but for now, I am trying on one range as it doesn't come as it should.
Here is how the case looks before running the code:

This my DESIRED outcome => the rows in the array where ID matches to defined name clear in the range:

My code does not repsond at all. No error message, nothing and within that no outcome I expect:
Option Explicit
Sub EraseArray()
Dim r As Long
Dim endRow As Long
Dim StartRow As Long
Dim TargetSheet As Worksheet
Const ColumnStart1 As Long = 2
Const ColumnEnd1 As Long = 5
Const ColumnStart2 As Long = 7 'to add
Const ColumnEnd2 As Long = 10 ' to add
Const ColumnStart3 As Long = 12 'to add
Const ColumnEnd3 As Long = 15 'to add
Const l_MyDefinedName As String = "ID"
Dim ColumnNo As Integer
Dim ClearRange As Range
Set TargetSheet = ThisWorkbook.Sheets("Sheet1")
With TargetSheet
StartRow = 8
Dim lngLastRow As Long
lngLastRow = .Cells(.Rows.Count, ColumnStart1).End(xlUp).Row '
Set ClearRange = .Range(.Cells(StartRow, ColumnStart1), .Cells(lngLastRow, ColumnEnd1))
Dim ID As String
ID = ThisWorkbook.Names(l_MyDefinedName).RefersToRange.Value
With ClearRange
Dim MatchID As String
For StartRow = 15 To ClearRange.Rows.Count
MatchID = Left(.Cells(StartRow, ColumnStart1), ColumnStart1)
If MatchID = ID Then
For ColumnNo = ColumnStart1 To ColumnEnd1
'
'*********Clear what is inside********'
TargetSheet.Cells(StartRow, ColumnNo).ClearContent
Next ColumnNo
StartRow = StartRow + 1
End If
Next StartRow
End With
End With
End Sub
Anybody who could help on that?
MsgBox "Sub EraseArray was called!"inside, but near the top of, the sub (preferably before anySet's,With's, or anything other thanConst's andDim's).For StartRow = 15if above it wasStartRow = 8? Also, in your exampleClearRange.Rows.Count= 7, so you're looping from 15 to 7, and it doesn't look like you meant toStep -1.