Remove punctuation but keep full number

dac1517

Board Regular
Joined
Sep 20, 2010
Messages
103
I have looked for a macro that will remove punctuation from column BQ, but all I have found thus far eliminates any 0's I have in front of the number. I need a macro that will remove punctuation but keep my number intact.

Numbers look: "001." need them to be "001"

Thanks for your help
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Perhaps:

Code:
Sub test()
Dim cell As Range
With CreateObject("VBScript.RegExp")
  .Global = True
  .Pattern = "\D"
  For Each cell In Intersect(ActiveSheet.UsedRange, Range("BQ:BQ"))
    If Len(cell.Text) > 0 Then
      cell.NumberFormat = "@"
      cell.Value = .Replace(cell.Text, "")
    End If
  Next cell
End With
End Sub
 
Upvote 0
The below will run on column BQ in every sheet of the activeworkbook:

Code:
Sub test()
Dim cell As Range
Dim ws As Worksheet
With CreateObject("VBScript.RegExp")
  .Global = True
  .Pattern = "\D"
  For Each ws In Worksheets
    For Each cell In Intersect(ws.UsedRange, ws.Range("BQ:BQ"))
      If Len(cell.Text) > 0 Then
        cell.NumberFormat = "@"
        cell.Value = .Replace(cell.Text, "")
      End If
    Next cell
  Next ws
End With
End Sub
 
Last edited:
Upvote 0
I put this code under "This Workbook" on Visual Basic window and when run it gives me a "438" error. What could be causing this?
 
Upvote 0
The code should go in a standard module.

From the menu in the Visual Basic Editor (VBE), choose Insert, then Module.
 
Upvote 0
It still gives me the same error message, even as a module. The debug function identifies the below line of code. Is there something wrong with this line of code? If not, I need to go back to the drawing board and figure out my files problem.

For Each cell In Intersect(ws.UsedRange, .wsRange("BQ:BQ"))
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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