ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA position of char in cell (https://www.excelbanter.com/excel-discussion-misc-queries/241244-vba-position-char-cell.html)

Jack Sons

VBA position of char in cell
 
Hi all,

I know the text in B2 contains char(10) at 2 positions. What code is needed
tot find the first an the second position?
TIA

Jack Sons
The Netherlands



Chip Pearson

VBA position of char in cell
 
Try something like

Dim S As String
Dim N1 As Long
Dim N2 As Long
S = "abc" & Chr(10) & "def" & Chr(10) & "ghi"
N1 = InStr(1, S, Chr(10), vbBinaryCompare)
N2 = InStr(N1 + 1, S, Chr(10), vbBinaryCompare)
Debug.Print N1, N2

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Tue, 1 Sep 2009 01:27:14 +0200, "Jack Sons"
wrote:

Hi all,

I know the text in B2 contains char(10) at 2 positions. What code is needed
tot find the first an the second position?
TIA

Jack Sons
The Netherlands


Jack Sons

VBA position of char in cell
 
CVhip,

Ah, the method is InStr.
Thank you, Chip, nice to hear again from you.

Jack.


"Chip Pearson" schreef in bericht
...
Try something like

Dim S As String
Dim N1 As Long
Dim N2 As Long
S = "abc" & Chr(10) & "def" & Chr(10) & "ghi"
N1 = InStr(1, S, Chr(10), vbBinaryCompare)
N2 = InStr(N1 + 1, S, Chr(10), vbBinaryCompare)
Debug.Print N1, N2

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Tue, 1 Sep 2009 01:27:14 +0200, "Jack Sons"
wrote:

Hi all,

I know the text in B2 contains char(10) at 2 positions. What code is
needed
tot find the first an the second position?
TIA

Jack Sons
The Netherlands





All times are GMT +1. The time now is 04:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com