Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,064
- Office Version
- 2016
- Platform
- Windows
I want to clean up some columns with Vba. I currently use this and it works fine more the most part, if the columns has text and numbers then it does not remove the item.
Results in red are not removing, all the phone numbers have the word "Call" which i can remove, however the other items have too many variables. I will not be able to work each one out the same as removing the word "Call"
PS. Some phone numbers have a "+" at the front e.g. +111222333
VBA Code:
Dim lastrow As Integer, i As Integer
Set wb = ThisWorkbook
With wb.Sheets("Data")
lastrow = .Cells(.Rows.Count, "c").End(xlUp).Row
For i = 2 To lastrow
'''phone numbers
If Not (Sheet9.Range("c" & i).Value Like "*#*#*#*#*") Then Sheet9.Range("c" & i).Value = "-"
If Not (Sheet9.Range("d" & i).Value Like "*#*#*#*#*") Then Sheet9.Range("d" & i).Value = "-"
If Not (Sheet9.Range("e" & i).Value Like "*#*#*#*#*") Then Sheet9.Range("e" & i).Value = "-"
If Not (Sheet9.Range("c" & i).Value Like "**#") Then Sheet9.Range("c" & i).Value = "-"
If Not (Sheet9.Range("d" & i).Value Like "**#") Then Sheet9.Range("d" & i).Value = "-"
If Not (Sheet9.Range("e" & i).Value Like "**#") Then Sheet9.Range("e" & i).Value = "-"
.Range("C" & i).Value = Replace(.Range("C" & i).Value, "Call", "")
.Range("D" & i).Value = Replace(.Range("D" & i).Value, "Call", "")
.Range("E" & i).Value = Replace(.Range("E" & i).Value, "Call", "")
Next i
End With
Results in red are not removing, all the phone numbers have the word "Call" which i can remove, however the other items have too many variables. I will not be able to work each one out the same as removing the word "Call"
PS. Some phone numbers have a "+" at the front e.g. +111222333