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

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Voltage Switch 1/16W Ceramic Wirewound Regulator[/TD]
[/TR]
[TR]
[TD]Ceramic Wirewound 1/10MW[/TD]
[/TR]
[TR]
[TD]5/100W Differential tactile fuse[/TD]
[/TR]
</tbody>[/TABLE]

To this

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Voltage Switch Ceramic Wirewound Regulator[/TD]
[/TR]
[TR]
[TD]Ceramic Wirewound[/TD]
[/TR]
[TR]
[TD]Differential tactile fuse[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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