gtd526
Well-known Member
- Joined
- Jul 30, 2013
- Messages
- 660
- Office Version
- 2019
- Platform
- Windows
Hello,
Using VBA:
Im trying to remove text from a cell if the last 4 digits are " - x" or " - y" or " - z". Any of the 3 criteria's.
The code I created:
Dim c As Range
For Each c In Range("T:T")
If c.Value = Right(c, 4) = " - y" Then
c = Left(c, Len(c) - 4)
End If
MsgBox c.Address 'just to see if its working 'c'
Next c
I've tried putting " " for the spaces, among other changes, but its not working.
There are formula's that work, but I want VBA to do it for me (all at once).
Thank you.
Using VBA:
Im trying to remove text from a cell if the last 4 digits are " - x" or " - y" or " - z". Any of the 3 criteria's.
NBA.xlsm | ||||||
---|---|---|---|---|---|---|
T | U | V | W | |||
1 | Eastern | W | L | Pct | ||
2 | Milwaukee - y | 54 | 14 | .794 | ||
3 | Toronto - x | 49 | 18 | .731 | ||
4 | Boston - x | 44 | 23 | .657 | ||
5 | Miami - z | 43 | 25 | .632 | ||
6 | Indiana - z | 42 | 26 | .618 | ||
7 | Philadelphia | 41 | 27 | .603 | ||
8 | Brooklyn | 32 | 35 | .478 | ||
NBA Standings-Yahoo |
The code I created:
Dim c As Range
For Each c In Range("T:T")
If c.Value = Right(c, 4) = " - y" Then
c = Left(c, Len(c) - 4)
End If
MsgBox c.Address 'just to see if its working 'c'
Next c
I've tried putting " " for the spaces, among other changes, but its not working.
There are formula's that work, but I want VBA to do it for me (all at once).
Thank you.