Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:01:22+00:00 2026-05-15T06:01:22+00:00

I have what seems like a simple problem with some data in Excel. I

  • 0

I have what seems like a simple problem with some data in Excel. I have a lot of data with leading spaces pasted from a web table, and I would like to get rid of the initial space. I cribbed the following code (I am completely new to VBA), but it doesn’t seem to work. When I step through it in the debugger it looks like an infinite loop. Any help would be appreciated!

Sub DoTrim()
  For Each cell In Selection.Cells
    If cell.HasFormula = False Then
      cell = Trim(cell)
    End If
  Next
End Sub

EDIT:
It does look like the TRIM function is running into problems with a “space” character. This code:

Sub DoTrim()
Dim cell As Range, areaToTrim As Range
Set areaToTrim = Selection.Cells
For Each cell In areaToTrim
    cell.Value = "MUPPET"
Next cell
End Sub

Changed the value of the cells, so I guess it’s a non-space whitespace! Any idea on how to get rid of those?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:01:23+00:00Added an answer on May 15, 2026 at 6:01 am

    If you have a non-printing character at the front of the string try this

    
    Option Explicit
    Sub DoTrim()
        Dim cell As Range
        Dim str As String
        Dim nAscii As Integer
        For Each cell In Selection.Cells
            If cell.HasFormula = False Then
                str = Trim(CStr(cell))
                If Len(str) > 0 Then
                    nAscii = Asc(Left(str, 1))
                    If nAscii &lt 33 Or nAscii = 160 Then
                        If Len(str) &gt 1 Then
                            str = Right(str, Len(str) - 1)
                        Else
                            strl = ""
                        End If
                    End If
                End If
                cell=str
            End If
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have what seems like a simple problem. I have a Spring web app,
This seems like a simple problem: I have a WF4 activity that guides the
ok it seems like a simple problem, but i am having problem I have
I have what seems like a simple arrangement: a list of tags in a
This seems like such a simple question. I have several Edit boxes on my
This seems like it should be so simple, but apparently it isn't. I have
I have an issue that seems like very flaky behavour, is this a problem
It seems like some tables are inheriting styles that they shouldn't. I have a
I have a android app that is quite simple it fetches data from the
I have an extremely simple JSON object that looks like the following: var data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.