![]() |
| If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Thanks in advance.
I have a macro where I need to get the row number from a range (like the 11 in "$G$11") becausen I will compare it with another row number later (if rownum1 < rownum2 then ...) The way I do it now is: 1 get the position of the first '$' from the right (I made a function like InStr, except it looks from the right end of string, not the left end) 2 get the right part of the string for as many chars as (total length of string - position of first '$' from left) ie for "$G$11": 1 position of first '$' from right is 3 2 length of string-position=row number length. 5-3=2, so get "11" Then I can compare "11" with another row number (like 6 or whatever). I am wondering if there is an easier way to do this, or is there a built-in command for this? I wanted to use InStr, but InStr looks for the first occurence of a string from the left, not right. I can't use right(string1,2) either because the row number might be "1" or "326" or "4355" or "65029", where the number of digits change. Any ideas? Thanks again. |
| Ads |
|
#2
|
|||
|
|||
|
Ian,
In Excel 2000 and later, there is a function called InStrRev which works like InStr but searches right to left. But I don't think you need to do all the string manipulation you're doing. If you have a string containing a valid address, just use the Row property to return the row number. For example, Dim S As String Dim RowNum As Long S = "$G$11" RowNum = Range(S).Row Debug.Print RowNum -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Ian Elliott" > wrote in message ... > Thanks in advance. > I have a macro where I need to get the row number from a > range (like the 11 in "$G$11") becausen I will compare it > with another row number later (if rownum1 < rownum2 > then ...) > The way I do it now is: > 1 get the position of the first '$' from the right (I made > a function like InStr, except it looks from the right end > of string, not the left end) > 2 get the right part of the string for as many chars as > (total length of string - position of first '$' from left) > > ie for "$G$11": > 1 position of first '$' from right is 3 > 2 length of string-position=row number length. 5-3=2, so > get "11" > Then I can compare "11" with another row number (like 6 or > whatever). > I am wondering if there is an easier way to do this, or is > there a built-in command for this? I wanted to use InStr, > but InStr looks for the first occurence of a string from > the left, not right. I can't use right(string1,2) either > because the row number might be "1" or "326" or "4355" > or "65029", where the number of digits change. > Any ideas? > Thanks again. > |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to find a text in a string without giving the position of the | Sreekanth | Excel Discussion (Misc queries) | 2 | April 15th 10 09:07 PM |
| Find position of first non-matching character | Greg Lovern | Excel Worksheet Functions | 18 | June 1st 08 01:52 AM |
| return a character at a certain position in a string of text | Miranda | Excel Worksheet Functions | 2 | April 23rd 07 05:05 AM |
| find nth position of a string | TUNGANA KURMA RAJU | Excel Discussion (Misc queries) | 6 | October 18th 05 01:25 PM |
| find position of a number in a string | fullers80 | Excel Worksheet Functions | 1 | September 6th 05 03:47 PM |