Removing everything from a cell that is not 8 characters long

mindbender

New Member
Joined
Oct 30, 2015
Messages
13
Is this possible to remove anything not 8 characters long from a cell in a column.

for example Column H has 4 rows (there is data in columns A-G as well but I am only looking at column H to make this change):
[TABLE="width: 421"]
<colgroup><col></colgroup><tbody>[TR]
[TD]1. NBS CM XTEND 14260 FXC041465 FXC041466, FXC041774[/TD]
[/TR]
[TR]
[TD]2. NBS "INSTALL" 9HB915543 ...+51[/TD]
[/TR]
[TR]
[TD]3. RET SS PBB009144[/TD]
[/TR]
[TR]
[TD]4. RET CONV BG0960335

Is there something I can do so that once updated the columns look like this:
1. FXC041465 FXC041466 FXC041774
2. 9HB915543
3. PBB009144
4. BG0960335[TABLE="width: 421"]
<colgroup><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Basically just the data with 8 characters separated by a single space.

Any insight would be greatly appreciated[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about
Code:
Sub mindbender()
   Dim Cl As Range
   Dim Sp As Variant
   Dim i As Long
   
   For Each Cl In Range("H1", Range("H" & Rows.Count).End(xlUp))
      Sp = Split(Cl)
      Cl.Value = ""
      For i = 0 To UBound(Sp)
         If Len(Sp(i)) = 9 Then Cl.Value = Cl.Value & " " & Sp(i)
      Next i
      Cl.Value = Trim(Cl.Value)
   Next Cl
End Sub
This works on 9 characters, not 8 as that is what your data is, but it will also include "INSTALL"
 
Upvote 0
How about
Code:
Sub mindbender()
   Dim Cl As Range
   Dim Sp As Variant
   Dim i As Long
   
   For Each Cl In Range("H1", Range("H" & Rows.Count).End(xlUp))
      Sp = Split(Cl)
      Cl.Value = ""
      For i = 0 To UBound(Sp)
         If Len(Sp(i)) = 9 Then Cl.Value = Cl.Value & " " & Sp(i)
      Next i
      Cl.Value = Trim(Cl.Value)
   Next Cl
End Sub
This works on 9 characters, not 8 as that is what your data is, but it will also include "INSTALL"

That is awesome - Thank you very much
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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