Remove number followed by period

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings I have an excel table and on row 2 from column B to column R (B:R) there is a number followed by a dot/period. For example 12., 13., 14. 15. 16. etc.
I am hoping to have a VBA remove the number and period. For example I have 21. FLEET after the VBA I will have only "FLEET".
I found in an old entry from Mr. Excel which I think will work. Except I only want it to apply to ROW2 between Columns B and R.

VBA Code:
Sub RemoveNumbersFromColumnB()
  Dim X As Long, R As Long, Data As Variant
  Data = Range("B1", Cells(Rows.Count, "B").End(xlUp))
  For R = 1 To UBound(Data)
    For X = 1 To Len(Data(R, 1))
      If Mid(Data(R, 1), X, 1) Like "[0-9]" Then Mid(Data(R, 1), X) = " "
    Next
    Data(R, 1) = Replace(Data(R, 1), " ", "")
  Next
  Range("B1").Resize(UBound(Data)) = Data
End Sub


Thank you so much,
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
If it is always at the beginning this should work.

VBA Code:
Sub RemoveNumbersFromRow()

  Dim X As Long, R As Long
  Dim rng As Range, arrData As Variant
  Dim iPoint As Long
  
  Set rng = Range("B2:R2")
  arrData = rng
  
  
  For R = 1 To UBound(arrData, 2)
    iPoint = InStr(arrData(1, R), ".")
    If iPoint <> 0 And IsNumeric(Left(arrData(1, R), iPoint)) Then
        arrData(1, R) = Trim(Replace(arrData(1, R), Left(arrData(1, R), iPoint), ""))
    End If
  Next R
    
  rng.Value2 = arrData

End Sub
 
Upvote 0
Solution
If it is always at the beginning this should work.

VBA Code:
Sub RemoveNumbersFromRow()

  Dim X As Long, R As Long
  Dim rng As Range, arrData As Variant
  Dim iPoint As Long
 
  Set rng = Range("B2:R2")
  arrData = rng
 
 
  For R = 1 To UBound(arrData, 2)
    iPoint = InStr(arrData(1, R), ".")
    If iPoint <> 0 And IsNumeric(Left(arrData(1, R), iPoint)) Then
        arrData(1, R) = Trim(Replace(arrData(1, R), Left(arrData(1, R), iPoint), ""))
    End If
  Next R
   
  rng.Value2 = arrData

End Sub
Thank you that is correct and very helpful.
 
Upvote 0
You haven't given us any real understanding of what your data actually looks like, so this may or may not work. IF there is ALWAYS a space after the dot that follows the number AND IF there are NO other dot-space character combinations anywhere else in the text, then this one-liner would work for you...
VBA Code:
Sub RemoveNumbersFromRow()
  Range("B2:R2").Replace "*. ", "", xlPart, , , , False, False
End Sub
 
Upvote 0
You haven't given us any real understanding of what your data actually looks like, so this may or may not work. IF there is ALWAYS a space after the dot that follows the number AND IF there are NO other dot-space character combinations anywhere else in the text, then this one-liner would work for you...
VBA Code:
Sub RemoveNumbersFromRow()
  Range("B2:R2").Replace "*. ", "", xlPart, , , , False, False
End Sub
I'm sorry I had had a chance to respond. I did get enough to complete what I needed. Yours was the old entry that I was referring to.
Thank you so much
 
Upvote 0
Thank you that is correct and very helpful.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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