![]() |
Return the first 2 letters of a Cell Value
I have a BeforeDoubleClick_Event that I want to use to intialize different
Userforms. My users will click on certain cells that contain reference numbers. Each number starts with two capital letters. The two letters will dictate which Userform is Initalized. How can I extract the first two letters of the cell value. For example: Select Case (FIRST TWO LETTER OF TARGET) Case PF 'code' Case EC 'code' End Select Thanks in Advance, Ryan |
Return the first 2 letters of a Cell Value
Is this what you are looking for...
Select Case Left$(Target.Value, 2) Rick "RyanH" wrote in message ... I have a BeforeDoubleClick_Event that I want to use to intialize different Userforms. My users will click on certain cells that contain reference numbers. Each number starts with two capital letters. The two letters will dictate which Userform is Initalized. How can I extract the first two letters of the cell value. For example: Select Case (FIRST TWO LETTER OF TARGET) Case PF 'code' Case EC 'code' End Select Thanks in Advance, Ryan |
Return the first 2 letters of a Cell Value
And you may want:
select case lcase(left(somecell.value,2)) case is = lcase("PF") ... case is = lcase("EC") You may want to do a comparison that isn't case sensitive. I figured PF and EC were not variables--they were strings. RyanH wrote: I have a BeforeDoubleClick_Event that I want to use to intialize different Userforms. My users will click on certain cells that contain reference numbers. Each number starts with two capital letters. The two letters will dictate which Userform is Initalized. How can I extract the first two letters of the cell value. For example: Select Case (FIRST TWO LETTER OF TARGET) Case PF 'code' Case EC 'code' End Select Thanks in Advance, Ryan -- Dave Peterson |
Return the first 2 letters of a Cell Value
Yes, that is what I needed! What does the $ do?
Thanks, Ryan "Rick Rothstein (MVP - VB)" wrote: Is this what you are looking for... Select Case Left$(Target.Value, 2) Rick "RyanH" wrote in message ... I have a BeforeDoubleClick_Event that I want to use to intialize different Userforms. My users will click on certain cells that contain reference numbers. Each number starts with two capital letters. The two letters will dictate which Userform is Initalized. How can I extract the first two letters of the cell value. For example: Select Case (FIRST TWO LETTER OF TARGET) Case PF 'code' Case EC 'code' End Select Thanks in Advance, Ryan |
Return the first 2 letters of a Cell Value
In VB/VBA, affixing a $ sign to a String function makes that function return
a pure String value; without the $ sign, String functions return Variants with a sub-type of String. If you need a pure String value (like for your Case tests), the pure String functions are faster executing than the Variant ones; however, unless you are using them in a very large loop structure, the time difference is pretty negligiable, so using it in this case does not really aid the execution speed in any noticeable way... I use it more from force of habit (as I come from the compiled VB world where I encountered the large loops much more often). Rick "RyanH" wrote in message ... Yes, that is what I needed! What does the $ do? Thanks, Ryan "Rick Rothstein (MVP - VB)" wrote: Is this what you are looking for... Select Case Left$(Target.Value, 2) Rick "RyanH" wrote in message ... I have a BeforeDoubleClick_Event that I want to use to intialize different Userforms. My users will click on certain cells that contain reference numbers. Each number starts with two capital letters. The two letters will dictate which Userform is Initalized. How can I extract the first two letters of the cell value. For example: Select Case (FIRST TWO LETTER OF TARGET) Case PF 'code' Case EC 'code' End Select Thanks in Advance, Ryan |
All times are GMT +1. The time now is 05:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com