Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ayden Smith   on Sep 30 In MS Office Category.

  
Question Answered By: Ralph Murray   on Sep 30

Your guidance
enabled me to write the following procedure. I am sure this can be
done more efficiently.

Sub TrimBlanks()


' Removes Leading Spaces -
' Be Sure to rename Wrksheets in 3 places and
' notice range begins on Row 4


Dim X As Object
Dim r As Integer
Dim c As Integer

Dim MyString, TrimString

' Be Sure to RENAME Wrksheets and
Worksheets("REP").Activate

Range("A4:A65336").Select

Do While ActiveCell.Value <> ""
Set X = ActiveCell

MyString = ActiveCell
TrimString = LTrim(MyString)

r = X.Row + 0
c = X.Column + 0

' Be Sure to RENAME Wrksheets and
Worksheets("REP").Cells(r, c).Value = TrimString

'__________________________________________________________
r = X.Row + 1
c = X.Column + 0
ActiveCell.Offset(1, 0).Activate

Loop

Range("B4:B65336").Select

Do While ActiveCell.Value <> ""
Set X = ActiveCell

MyString = ActiveCell
TrimString = LTrim(MyString)

r = X.Row + 0
c = X.Column + 0

' Be Sure to RENAME Wrksheets and
Worksheets("REP").Cells(r, c).Value = TrimString

'__________________________________________________________
r = X.Row + 1
c = X.Column + 0
ActiveCell.Offset(1, 0).Activate

Loop

End Sub

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Need to trim leading spaces from cells Or get search suggestion and latest updates.


Tagged: