Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for spaces at beginning of string 1

Status
Not open for further replies.

nwallac1

Programmer
Apr 30, 2007
6
US
I am having a problem using the left function to check for spaces at the beginning of a string. using this code:

If Left(ActiveCell, 5) = " " Then activecell.offset(1,0).activate

I am trying to skip any string that begins with 5 spaces. The code above does not seem to work to accomplish this goal. Does anyone have any suggestions about how to better go about this?
 
How about using LTrim:
Code:
if len(activecell.txt)-len(LTrim(activecell.text))=5 then

_________________
Bob Rashkin
 
Hi nwallac1:

It worked for me with 5 spaces within the quotes ... so make sure there are 5 spaces within the quote marks.

Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
 
While using ltrim would be nice, it is not a possibility in this case. I am trying to eliminate those cells that begin with 5 or more spaces from my search. I chose 5 as a safe number that would distinguish the cells I want from the cells I do not want. thus, I am still having many problems.
 




I would not use Select either. Using the Select or Activate methods is not a good programming practice for range referencing.

Skip,

[glasses] [red][/red]
[tongue]
 
I am trying to eliminate those cells that begin with 5 or more spaces from my search.
Ah yeah! Finally some more info.
Keep it rolling, and you might not need five spaces in the first place!
:p

==> What are you trying to do and can't these unwanted cells not be distinguished in any other way?

==> With a search, you don't want to actually activate any cell anyway, do you?

Hence, a simple
Code:
dim ran as range, c as cell
set ran=Selection.Find(What:=.......).Activate
for each c in ran
 if not left(c,5)="     " then
   'do your thing
 end if
next c
[ponder]

[blue]Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates[/blue]
 

Code:
set ran = [b]ActiveSheet.Cells[/b].Find(What:=.......)   [red][S][b].Activate[/b][/s][/red]
...

Skip,

[glasses] [red][/red]
[tongue]
 




Yup, Gerry. Hate to sound like a broken record, but...

Do kids today know what a broken record sounds like?

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top