Help Needed to Remove Text From Cells

JPatty

New Member
Joined
Sep 21, 2022
Messages
14
Office Version
  1. 365
  2. 2019
  3. 2011
Platform
  1. Windows
I need help with VBA code to remove letters preceding numbers in columns B and C starting at B9 looping through.
Sheet1 is present state and the code would need to change the cells to appear like in Sheet2.
Ay help would be appreciated!


Remove Text Test.xlsx
C
18
Sheet1


Remove Text Test.xlsx
B
25
Sheet2
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I see no sample data at all? I tried copy/paste anyway and got nothing.
 
Upvote 0
My apologies.

Remove Text Test.xlsx
ABCDE
1
2Red
3Yellow
4Black
5Blue
6
7
8T&NT&N2
9Red-Blue: 123-456Red-Blue: 123,456,678,123
10Blue-Red Purple: 678-789Yellow-Pink Purple: Red 678,789
11Yellow-Pink Purple: 678-678Yellow-Pink Purple: 678-678
12Yellow-Pink Purple: Red 678,789Blue-Red Purple: 678-789
13Red-Blue: 123,456,678,123Red-Blue: 123-456
14
15
16
17
18
19
20
21
Sheet1


Remove Text Test.xlsx
ABCDE
1
2Red
3Yellow
4Black
5Blue
6
7
8T&NT&N2
9123-456123,456,678,123
10678-789678,789
11678-678678-678
12678,789678-789
13123,456,678,123123-456
14
15
16
17
18
19
20
21
Sheet2
 
Upvote 0
This assumes the number portion is always preceded with a ":"
Substitute your sheet name and try
VBA Code:
Sub RemoveText()
Dim rng As Range, rng2 As Range
Dim Lrow As Long

Lrow = Range("B:C").Find("*", , , , xlByRows, xlPrevious).Row
Set rng = Sheets("4").Range("B9:C" & Lrow)
     For Each rng2 In rng
          If InStr(1, rng2, ":") > 0 Then
               rng2.Value = Mid(rng2, InStr(1, rng2, ":") + 1)
          End If
     Next

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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