PDA

View Full Version : [SOLVED] Delete the value of cell that start by char with exception .



parscon
03-10-2018, 01:11 AM
Hello I have a VBA that it will check column A and delete the cell value start with character ... now i need to add a exception . that mean if the cell value start with CH or SA ignore them .



Sub DeleteRowIfCellValueStartswithoutANumber()
Dim i As Long

For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If IsNumeric(Left(Range("A" & i), 1)) = False Then Rows(i).Delete
Next i

End Sub

werafa
03-10-2018, 01:21 AM
testStr = left(Range("A" & i),2)

if teststr = "CH" or teststr = "SA" then
'do nothing
else
'mycode
end if

Hightree
03-10-2018, 05:05 AM
Hello I have a VBA that it will check column A and delete the cell value start with character ... now i need to add a exception . that mean if the cell value start with CH or SA ignore them .



Sub DeleteRowIfCellValueStartswithoutANumber()
Dim i As Long

For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If IsNumeric(Left(Range("A" & i), 1)) = False Then
If Left(Range(“A” & I),2)<>”CH” And Left(Range(“A” & i)<>”SA” Then
Rows(i).Delete
End If
End If
Next i

End Sub

Hightree
03-10-2018, 05:06 AM
Hello I have a VBA that it will check column A and delete the cell value start with character ... now i need to add a exception . that mean if the cell value start with CH or SA ignore them .
Sub DeleteRowIfCellValueStartswithoutANumber() Dim i As Long For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1 If IsNumeric(Left(Range("A" & i), 1)) = False ThenIf Left(Range(“A” & I),2)”CH” And Left(Range(“A” & i)”SA” ThenRows(i).DeleteEnd IfEnd If Next i End Sub

parscon
03-10-2018, 05:20 AM
Thank you I fixed the code and this is the correct and working one . Thanks for all helps.



Sub DeleteRowIfCellValueStartsWithANumber()

Dim i As Long


For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If IsNumeric(Left(Range("A" & i), 1)) = False Then
If Not (Left(Range("A" & i), 2)) = "CH" Or (Left(Range("A" & i), 2)) = "ZM" Then
Rows(i).Delete
End If
End If
Next i

End Sub