VBA : Remove Number, Extra Spaces, Mark (.) from a Text

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,089
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all.

i need vba code to remove series number from front text, remove extra spaces, mark dot (.)
i want the code work in any sheet name, cause i want to make code as personal macro/excel add-ins
the code work step:
- select range/cell then click/run macro
here this sample
before run macroafter run macro
1. John WeJohn We
2. Sisca MadameSisca Madame
12.Frans BonjourFrans Bonjour
124. Salsa Micro GavSalsa Micro Gav


anyone would help me, greatly appreciated..

susanto
 
It doesn't for me if the text is on Sheet1 (that is the sheet whose codename is Sheet1 not the tab name) and that sheet is not the active sheet.
If you are using Evaluate on a non-active sheet you need to specify the address in the evaluate function as 'External'
Peter I was already in the process of updating my post ;). See the updated post.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Peter I was already in the process of updating my post ;). See the updated post.
:biggrin: I edited mine too. That code does not work for me if the data to be manipulated is on Sheet1 and that sheet is not the active sheet. See my updated last post about specifying the address as external.
 
Upvote 0
:biggrin: I edited mine too. That code does not work for me if the data to be manipulated is on Sheet1 and that sheet is not the active sheet. See my updated last post about specifying the address as external.

my updated code in #9 will work even if sheet1 is not active.
 
Upvote 0
I'm sorry, I had two sample workbooks open and had your updated code in the wrong workbook. :oops:
Yes, your updated code works fine. (y)
Thats ok. I am sure this discussion would help OP. We all make these mistakes. My first mistake (which I rarely do is leave my objects unqualified). My second (Again, this is something which I rarely do) was to put and test the code in Sheet Code Module and not in the regular Module :rolleyes:.

Sigh, I guess it is one of those days...
 
Upvote 0
hi guys...thank you but
how if the range is not always in col A, i want the range is dynamic, depend on where is data place
modified the new step:
1. at first, select your range
2. running code/macro
 
Upvote 0
Rich (BB code):
With Range("A2", Range("A" & Rows.Count).End(xlUp))
With Selection

.. and that takes the whole active v non-active sheet discussion out of the question. :LOL:
 
Upvote 0
Did you try mine, it is based on selecting a range, then running the code/macro?
 
Upvote 0
Hi, the code below should work:
VBA Code:
Sub forSplitOnPeriod()
  Dim cell As Range
 
  On Error Resume Next
 
  For Each cell In Selection
    cell.Value = Trim(Split(cell.Value, ".")(1)) 'Split on period and remove lead space
  Next cell
End Sub
hi i found new problem, how about if data not consistent use mark (.), sometimes contains mark (.) sometimes not contains mark (.)
like this sample
new caseafter run macro
1. John WeJohn We
2 Sisca MadameSisca Madame
12 Frans BonjourFrans Bonjour
124. Salsa Micro GavSalsa Micro Gav
 
Upvote 0
Assuming that you are selecting cells in a single column try this. It removes anything before the first letter.
(If you could be selecting cells in multiple contiguous columns it is easily adaptable)

VBA Code:
Sub Tidy_Up()
  Dim RX As Object
  Dim a As Variant
  Dim i As Long
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "^[^A-Za-z]*"
  With Selection
    a = .Value
    For i = 1 To UBound(a)
      a(i, 1) = RX.Replace(a(i, 1), "")
    Next i
    .Value = a
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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