Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND 1 char in cell of any 3 char =True Nastech Excel Discussion (Misc queries) 5 April 26th 08 02:17 PM
How do i get the last position of a char (space) in a string? EsPoNjOsO Excel Worksheet Functions 1 October 12th 06 11:55 AM
8500 cells with phone number(7 char.), wishing to add area code (10 char.) [email protected] Excel Discussion (Misc queries) 6 March 10th 06 05:13 PM
finding char within a cell Jordan Excel Worksheet Functions 4 June 17th 05 03:00 AM
How do I remove Char(160) from a cell? Dave Excel Worksheet Functions 2 February 3rd 05 02:06 PM


All times are GMT +1. The time now is 01:19 PM.

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

About Us

"It's about Microsoft Excel"