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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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