Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Search number in a string (excel vba)

Hello,
I have a string in cell(1,1) with a number in. For example: "This is
sensor_01" (it's not always te same string, it can be longer or shorter).
Now I want to copy this to cell(2,1) en increase the numer in the string
"This is sensor_02".
Does anybody know how to search for a number in a string, increase it and
put it back?
Jac


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Search number in a string (excel vba)

Jac,

Try something like the following:

Dim S As String
Dim Pos As Integer
Dim N As Integer

S = Range("A1").Text
Pos = InStr(1, S, "_")
N = CInt(Mid(S, Pos + 1))
S = Left(S, Pos) & Format(N + 1, "00")
Range("A2").Value = S


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jac" wrote in message
.. .
Hello,
I have a string in cell(1,1) with a number in. For example:

"This is
sensor_01" (it's not always te same string, it can be longer or

shorter).
Now I want to copy this to cell(2,1) en increase the numer in

the string
"This is sensor_02".
Does anybody know how to search for a number in a string,

increase it and
put it back?
Jac




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
Search for number after specific text in string AMH Excel Worksheet Functions 8 September 4th 09 03:05 PM
search text string for number Sooz Excel Discussion (Misc queries) 10 August 24th 09 04:20 PM
search string for number value samuel Excel Discussion (Misc queries) 3 May 13th 08 10:05 PM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
How do I search for a string across multiple worksheets in Excel? BBiletch Excel Worksheet Functions 2 April 5th 05 11:59 PM


All times are GMT +1. The time now is 07:04 AM.

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

About Us

"It's about Microsoft Excel"