VBA Remove Spaces Between Numbers and Characters fi

VBA Remove Spaces Between Characters and Numbers within Range in Excel

VBA Delete Spaces Between numbers and characters within range in Excel. We can use Find and Replace VBA functions to remove spaces completely between characters and numbers.

Macro to Remove Spaces Between characters and Numbers within Range in Excel VBA

Let us see the example macro to Remove Spaces within Range in Excel VBA.

'Macro to Remove Spaces Between Numbers and Characters within Range in Excel VBA
Sub VBA_Remove_Spaces_Between_Numbers_Characters()

    'Variable Declaration
    Dim rRange As Range
    
    Set rRange = ActiveSheet.Range("A1:G200")
    rRange.Replace What:=Space(1), Replacement:="", _
          SearchOrder:=xlByColumns, MatchCase:=True
          
    Set rRange = rRange.Find(What:=Space(1))
    
    If Not rRange Is Nothing Then
        'Procedure repeats until all spaces are removed
       Call VBA_Remove_Spaces_Between_Words
    End If
    
End Sub

Here is the output screenshot of above macro code.

VBA Remove Spaces Between Numbers and Characters

Instructions to use Macro

Here are the instructions to use above macro in Visual basic editor.

  • Open Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see output on the screen
  • Find above specified output screenshot.

Other Useful VBA Text and String Functions

Click on below specified links to learn more about VBA functions.

VBA Text and String Functions VBA FIND Function VBA REPLACE Function




Leave a Comment

Your email address will not be published. Required fields are marked *