Hi Guys,
I am trying to create a function that loops through code and deletes columns based on a selector. This selector is whether the cell.value starts with the number 1 or 2 (both of these are passed as a string).
This code is below.
The problem that I am having is that whilst the logic works, it doesn't delete the rows as expected, i.e: if I replaced rngCell.EntireRow.Delete with something like rngcell.Offset(0,5).value = "Please Delete This Row" it would totally work.
Note: This is what I am passing though to it.
I am trying to create a function that loops through code and deletes columns based on a selector. This selector is whether the cell.value starts with the number 1 or 2 (both of these are passed as a string).
This code is below.
Code:
Public Sub deleteData(rngColumn As Range, strSelector As String)
Debug.Print rngColumn.Address
Dim rngCell As Range
For Each rngCell In rngColumn
Debug.Print rngCell.Address
Debug.Print Left(CStr(rngCell.Value), 1) = strSelector
If Left(CStr(rngCell.Value), 1) = strSelector Then
rngCell.EntireRow.Delete
End If
Next
End Sub
The problem that I am having is that whilst the logic works, it doesn't delete the rows as expected, i.e: if I replaced rngCell.EntireRow.Delete with something like rngcell.Offset(0,5).value = "Please Delete This Row" it would totally work.
Note: This is what I am passing though to it.
Code:
Sheets("Macros").Activate Call deleteData(Range("T1:T25"), "2")