Dellete column F all the values that dont have 3 digits

Excelnewbie001

Board Regular
Joined
Jan 25, 2017
Messages
79
Hope someone can help I am looking for a macro to delete all the values in colum F that dont have 3 digits. here is a sample data so in this sample below 1,3, must be deleted 2,,2 must be deleted. 4,, must be deleted. So only Numbers with 3 digits must not be deleted.Thanks for any help -this must be simple for vba programmer

1, 2, 1
1, 3,
1, 3, 0
2, , 2
2, 2, 0
2, 1, 1
3, , 1
3, 1, 0
4, ,
4, , 0
4, 0, 0
, , 4
, 4, 0
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
if there is always a space after a comma, delete all cells where len= <7
for j=1 to 1000
if len(cells(j,1))<7 then cells(1,1)=""
next j
end sub
 
Upvote 0
if there is always a space after a comma, delete all cells where len= <7
for j=1 to 1000
if len(cells(j,1))<7 then cells(1,1)=""
next j
end sub

Is this correct ?
Code:
Sub Deletechar
for j=1 to 1000
if len(cells(j,1))<7 then cells(1,1)=""
next j
end sub
[CODE]
 
Last edited:
Upvote 0
Try this
Code:
Sub Del_Values()
  Dim a As Variant
  Dim i As Long
  
  a = Range("F1", Range("F" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    If Not a(i, 1) Like "#, #, #" Then a(i, 1) = Empty
  Next i
  Range("F1").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0
Try this
Code:
Sub Del_Values()
  Dim a As Variant
  Dim i As Long
  
  a = Range("F1", Range("F" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    If Not a(i, 1) Like "#, #, #" Then a(i, 1) = Empty
  Next i
  Range("F1").Resize(UBound(a)).Value = a
End Sub

Peter your a legend it works but may I please ask you just to move the data up with other words delete empty cells -then its perfect -Thank you for the code thus far its spot on -See below the output but there is spaces if I can move it up it will be 100% thank you you are very good

1, 2, 1
1, 3, 0
2, 2, 0
2, 1, 1
3, 1, 0
4, 0, 0

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0
.t may I please ask you just to move the data up with other words delete empty cells
Sure
Code:
Sub Del_Values_v2()
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long
  
  a = Range("F1", Range("F" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If a(i, 1) Like "#, #, #" Then
      k = k + 1
      b(k, 1) = a(i, 1)
    End If
  Next i
  Range("F1").Resize(UBound(b)).Value = b
End Sub
 
Upvote 0
Here is another macro that you can try...
Code:
[table="width: 500"]
[tr]
	[td]Sub Del_Values()
  Dim Addr As String
  Addr = "F1:F" & Cells(Rows.Count, "F").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF(ISNUMBER(FIND("",,"",SUBSTITUTE("",""&@&"","","" "",""""))),"""",@)", "@", Addr))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Another possibility :
Code:
Sub Foo()
Dim r$
r = Range([F1], Cells(Rows.Count, "F").End(xlUp)).Address
Range(r) = Evaluate("=IF(LEN(" & r & ")<7,""""," & r & ")")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,316
Messages
6,124,228
Members
449,149
Latest member
mwdbActuary

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