FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,364
- Office Version
- 365
- 2016
- Platform
- Windows
I'm hoping to use the evaluate function in VBA to keep everything before the dash in row 1. If there isn't a dash in the data then just keep what's already in the cell.
Example data:
The first row is row 1, and just using row 2 to show you what I want replaced directly in the cells of row 1.
This is close, but the .value line is not right.
Example data:
POV - Private Vehicle | CAT | MPH - Miles Per Hour |
POV | CAT | MPH |
The first row is row 1, and just using row 2 to show you what I want replaced directly in the cells of row 1.
This is close, but the .value line is not right.
VBA Code:
Sub RemoveData()
Dim LastCol As Long: LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
With Range(Cells(1, 1), Cells(1, LastCol))
.Value = Evaluate("IF(ISNUMBER(SEARCH(""-"",@)),LEFT(@,FIND(""-"",@)-2),@))
End With
End Sub