VBA to Remove ASCII Character 32

legalhustler

Well-known Member
Joined
Jun 5, 2014
Messages
1,171
Office Version
  1. 365
Platform
  1. Windows
I have two sheets ("Old" and "New") with various range of data and would like them to be formatted the same so that it removes ASCII character 32 and replaces them with a null text string "".

Can someone help with creating this macro.


Thanks.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,
ASCII character 32 is space?
Ctrl + H ?

Yes - ASCII character 32 is space, but I am looking specifically for a code to do this as it is just a small subset of a larger code that compares the two sheets. Thanks.
 
Upvote 0
Cells.Replace Chr(160), " ", xlPart

I tried the above code but it's not removing the extra hard coded spaces. I needed to replace code 32 from all cells with no spaces ("") or with code 160. Code 32 means it has space and code 160 means non-breaking space.

On one sheet a text like "Hello World" has code 32 and on another sheet the same text has code 160. All the characters need to be in the same format. Therefore, I want to replace code 32 from the one sheet to code 160.

Please advise. Thanks.
 
Upvote 0
This is my entire code (note the bold part):

Code:
Sub UnmergePasteValuesDeleteBlankRows()
Dim LR As Long, Rw As Long, delRNG As Range, ws As Worksheet

For Each ws In ActiveWorkbook.Sheets
    Select Case ws.Name
        Case Is = "Old", "New"

    LR = ws.UsedRange.Rows.Count
    
    With ws.UsedRange
        .UnMerge
        .Value = .Value
        [B]Selection.Replace Chr(32), "", xlPart[/B]

    End With
    
    On Error Resume Next
        
    For Rw = 1 To LR
        If WorksheetFunction.CountA(ws.Rows(Rw).EntireRow) = 0 Then
            If delRNG Is Nothing Then Set delRNG = ws.Rows(Rw) Else Set delRNG = Union(delRNG, ws.Rows(Rw))
        End If
    Next Rw
        
    If Not delRNG Is Nothing Then delRNG.EntireRow.Delete xlShiftUp
    Set delRNG = Nothing
    End Select
Next ws

End Sub
 
Upvote 0
Issue resolved.

I used the following VBA code: Cells.Replace Chr(32), Chr(160), xlPart

Now both sheets has the same ascii codes

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

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