+ Reply to Thread
Results 1 to 5 of 5

Loop Through Column and Delete Space

Hybrid View

EnigmaMatter Loop Through Column and... 10-01-2014, 10:13 AM
stnkynts Re: Loop Through Column and... 10-01-2014, 10:51 AM
Vikas_Gautam Re: Loop Through Column and... 10-01-2014, 10:52 AM
EnigmaMatter Re: Loop Through Column and... 10-01-2014, 11:16 AM
JOHN H. DAVIS Re: Loop Through Column and... 10-01-2014, 11:20 AM
  1. #1
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Loop Through Column and Delete Space

    Hello,

    I have a number of Cells in a Column that contain a space before the text contents (that shouldn't have a space before the text contents). For example " Fake Customer Name".

    How do I loop through the Column to delete the SPACE, but if there is no space before the text, don't delete anything.

    Thank You in Advance; I always appreciate your help.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Loop Through Column and Delete Space

    Sub Remove_Space()
    Dim rCell As Range
    
    For Each rCell In Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
        If Len(rCell) <> 0 Then
            rCell.Value = Trim(rCell.Value)
        End If
    Next rCell
    
    End Sub
    Do you need this post and the other combined into 1 macro?

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Loop Through Column and Delete Space

    Use Trim Function..
    or try this code..
    Sub TrimCell()
    set x= application.inputbox("set your Target Range", Type:=8)
    For each cell in x
    cell=Trim(cell)
    next
    End Sub
    will do the job...
    Last edited by Vikas_Gautam; 10-01-2014 at 10:54 AM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  4. #4
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Loop Through Column and Delete Space

    stnkynts,

    1.) Excellent Solution.
    2.) Took me way too long to figure out your user name.
    Thank You,

    EnigmaMatter

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Loop Through Column and Delete Space

    Maybe:

    Sub EnigmaMatteryy()
    Dim i As Long
    For i = Range("A" & Rows.count).End(3).Row To 2 Step -1
        If Left(Range("A" & i), 1) = " " Then
            Range("A" & i).Value = Right(Range("A" & i), Len(Range("A" & i)) - 1)
        End If
    Next i
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Loop Through Column B and insert a space in each cell, without deleting the contents.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2014, 10:10 AM
  2. Macro doesn't delete space at the end of every number in column
    By Will03 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-02-2014, 02:48 PM
  3. [SOLVED] Delete that Extra Space Through the Entire Column
    By kooldis in forum Excel General
    Replies: 6
    Last Post: 05-07-2014, 03:25 AM
  4. [SOLVED] How do I delete an extra space in every cell in a column?
    By iamjbunni in forum Excel General
    Replies: 2
    Last Post: 04-21-2006, 01:14 PM
  5. [SOLVED] Loop column A and delete and move on condition
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-15-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1