VBA Remove variable text from a string

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi , Is there a way to remove variable text from a string in a cell, there will be variable rows of data that may or may not contain the W/MW values, and it's not case sensitive either. Can someone help with this please

From this

Voltage Switch 1/16W Ceramic Wirewound Regulator
Ceramic Wirewound 1/10MW
5/100W Differential tactile fuse

<tbody>
</tbody>

To this

Voltage Switch Ceramic Wirewound Regulator
Ceramic Wirewound
Differential tactile fuse

<tbody>
</tbody>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi, here is one way you could try - assumes your values are in column A - test on a copy of your data.

Code:
Sub M()
Dim a As Variant, b As Variant, i As Long
a = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Value
For i = 1 To UBound(a)
    For Each b In Split(a(i, 1), " ")
        If UCase(b) Like "*/*W" Then
            a(i, 1) = Replace(a(i, 1), b, "")
        End If
    Next b
    a(i, 1) = Application.Trim(a(i, 1))
Next i
Range("A1").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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