A Microsoft Excel forum. ExcelBanter

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.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How find character position # in string from right end? Or how get range row num



 
 
Thread Tools Display Modes
  #1  
Old December 17th 03, 03:50 PM posted to microsoft.public.excel.programming
Ian Elliott[_3_]
external usenet poster
 
Posts: 8
Default How find character position # in string from right end? Or how get range row num

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  
Old December 17th 03, 03:56 PM posted to microsoft.public.excel.programming
Chip Pearson
external usenet poster
 
Posts: 7,247
Default How find character position # in string from right end? Or how get range row num

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 10:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004-2013 ExcelBanter.
The comments are property of their posters.