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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for the first character in an excel field with VBA

Status
Not open for further replies.
Jul 21, 2009
29
US
Within an Excel macro, I want to check if the first letter of a cell entry is the letter z in small case.

I tried:
If Left(activecell.offset(-1,5).characters.value,1)="z" Then
But this returns an error.

Following the pattern of someone's answer on a different help site, I then tried to just go to the cell and use the following code:
If Left(activecell.characters.value,1)="z" Then
But again I got an error message.

How can I check to see if the first letter of an entry begins with the letter "z" within an Exel macro as the condition of an if statement?
 

Hi,

So you are not testing the ActiveCell, but the cell ON ROW ABOVE and FIVE COLUMNS TO THE RIGHT of the Activecell?
Code:
If LCase(Left(activecell.offset(-1,5).value,1))="z" Then
...
of course if your ActiveCell is in ROW 1, TILT!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I've got it. The macro designates the starting cell before the rest of the code runs, so there is no issue about being in row 1. Thank you for the response.
 



The macro designates the starting cell ...

If that's the case, then there is probably no need for Selecting or ActiveCell in your macro.

Post your entire code for tips.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top