vba remove unwanted text

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
684
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I want to remove unwanted text "(35-11)" from BF:BF. I have the following macro, but it doesn't work.
Thank you.

VBA Code:
Sub Test()
    
    Sheets("TeamRankings").Select 'Teamrankings
    'vs Rank
        Application.ScreenUpdating = False
        lastRow = Cells.Find("(", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For Each Rng In Range("BF3:BF" & lastRow)
            If InStr(Rng, "(") > 0 Then
                Rng = Mid(Rng, 1, WorksheetFunction.Find("(", Rng) - 2) 'rid of extra space
            End If
        Next Rng
        Application.ScreenUpdating = True

End Sub


NBA.xlsm
BDBEBFBGBHBIBJBKBLBM
2 RankTeamRatingv 1-5v 6-10v 11-16HiLowLast
3 1Utah (35-11)8.15-37-28-31121
4 2LA Clippers (32-17)5.84-33-67-3252
5 3Milwaukee (29-17)5.42-53-47-4143
6 4Phoenix (32-14)4.83-37-19-24144
7 5Denver (29-18)4.54-44-56-35135
8 6Philadelphia (32-15)4.21-66-17-24116
9 7LA Lakers (30-17)3.92-52-35-4177
10 8Brooklyn (32-15)3.46-14-28-2298
11 9Dallas (24-21)24-82-26-43169
12 10Boston (23-24)1.75-40-68-561310
TeamRankings
Cell Formulas
RangeFormula
BD2:BD12BD2=IF(BF:BF="Milwaukee","MIL",IF(BF:BF="LA Lakers","LAL",IF(BF:BF="Dallas","DAL",IF(BF:BF="Boston","BOS",IF(BF:BF="LA Clippers","LAC",IF(BF:BF="Toronto","TOR",IF(BF:BF="Utah","UTA",IF(BF:BF="Houston","HOU",IF(BF:BF="Denver","DEN",IF(BF:BF="Miami","MIA",IF(BF:BF="Okla City","OKC",IF(BF:BF="Philadelphia","PHI",IF(BF:BF="Indiana","IND",IF(BF:BF="New Orleans","NO",IF(BF:BF="San Antonio","SAN",IF(BF:BF="Brooklyn","BRK",IF(BF:BF="Portland","POR",IF(BF:BF="Phoenix","PHX",IF(BF:BF="Orlando","ORL",IF(BF:BF="Memphis","MEM",IF(BF:BF="Sacramento","SAC",IF(BF:BF="Minnesota","MIN",IF(BF:BF="Detroit","DET",IF(BF:BF="Chicago","CHI",IF(BF:BF="Washington","WAS",IF(BF:BF="New York","NYK",IF(BF:BF="Atlanta","ATL",IF(BF:BF="Charlotte","CHA",IF(BF:BF="Golden State","GS",IF(BF:BF="Cleveland","CLE",""))))))))))))))))))))))))))))))
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You could use the Find/Replace dialog for that. Select the data, then Ctrl+H, enter:

(*

(there's a space at the beginning) in the Find box, then leaving the Replace box empty, press Replace All.
 
Upvote 0
Try
VBA Code:
                Rng.Value = Mid(Rng, 1, WorksheetFunction.Find("(", Rng) - 2) 'rid of extra space
 
Upvote 0
Solution
In addition to Fluff's needed change, you may also want to change this row:
VBA Code:
lastRow = Cells.Find("(", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
to this:
VBA Code:
LastRow = Cells(Rows.Count, "BF").End(xlUp).Row
so it runs specifically against column BF.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
In addition to Fluff's needed change, you may also want to change this row:
VBA Code:
lastRow = Cells.Find("(", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
to this:
VBA Code:
LastRow = Cells(Rows.Count, "BF").End(xlUp).Row
so it runs specifically against column BF.
I incorporated your change in addition to Fluff's.
Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top