Removing data less than 3 characters between spaces

CMSREPORTS

New Member
Joined
Nov 29, 2018
Messages
10
Office Version
  1. 2013
Platform
  1. Windows
I have a data set which contains a series of numbers. The only relevant numbers are the ones greater than 4 characters. I am looking to strip everything else out from the cell. Thanks-


SampleDesired result
65 22 32 66 22556655
22556655​
98 665522 12 13 11
665522​
12 12 13 222
12​
12 6666​
6666​
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I can't offer a formula but could probably come up with some code that you could run against a sheet. I presume the result goes in the same cell as the original data, and if not >4 characters it all gets deleted?
But 6666 is not greater than 4 characters?
 
Upvote 0
Could there be multiple numbers of 4 or more characters in a single cell, or just one?
 
Upvote 0
It can be more than 1 set. The whole purpose of the exercise is to strip out irrelevant data.
I am looking for larger sequences to match employee information. I found a solution that works for me.
we can close this

I'll share it here. It certainly isnt my own.

[‎3/‎20/‎2023 5:13 PM]
Sub removeSmallWords()
ScreenUpdating = False

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("ServerData")

last_s = ws.Cells(1048576, 1).End(xlUp).Row
Dim rng As Range


Set rng = Range("BF2:BF" & last_s)

Dim stringArray() As String
Dim newString As String

For Each cell In rng
newString = ""
stringArray = Split(cell.Text)

For i = 0 To UBound(stringArray)
If Len(stringArray(i)) > 3 Then
newString = newString & " " & stringArray(i)
End If
Next i

cell.Value = Trim(newString)
Next cell

ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Glad you sorted it & thanks for letting us know.
 
Upvote 0
FWIW, this is what I came up with last night. Maybe it will assist someone else in the future. However, it's based on >4.
VBA Code:
Sub GrabFiveOrMore()
Dim ary() As String
Dim Lrow As Long
Dim i As Integer, n As Integer
Dim blnGreater As Boolean

Lrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lrow
     blnGreater = False
     ary() = Split(Trim(Cells(i, 1)), " ")
     For n = 0 To UBound(ary)
          If Len(ary(n)) > 4 Then
               Cells(i, 1) = ary(n)
               blnGreater = True
               Exit For
          End If
     Next
     If Not blnGreater Then Cells(i, 1) = ""
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

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