Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Incremanting text

Code please for incrementing text. For instance:



Text "D01-003" is in E7 and I need "D01-004" in E11



The following works but results in "D01-4" but I must maintain the "000"
format of the right three characters which need to go beyond "100"



Sub test()

Cells(11, 5) = Left(Cells(7, 5), 4) & (Right(Cells(7, 5), 3) + 1)

End Sub



Many thanks - in anticipation.



Francis Hookham


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Incremanting text

The function you're looking for is Format().

I'd use:

Cells(11, 5).Value = Left(Cells(7, 5).Value, 4) _
& Format(Mid(Cells(7, 5).Value, 5) + 1, "000")

With Mid(), you can just specify the starting position and xl's VBA will take
the rest of the string. (Different from the =mid() worksheet function.)


Francis Hookham wrote:

Code please for incrementing text. For instance:

Text "D01-003" is in E7 and I need "D01-004" in E11

The following works but results in "D01-4" but I must maintain the "000"
format of the right three characters which need to go beyond "100"

Sub test()

Cells(11, 5) = Left(Cells(7, 5), 4) & (Right(Cells(7, 5), 3) + 1)

End Sub

Many thanks - in anticipation.

Francis Hookham


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Incremanting text

Many thanks, especially the Mid() tip - I did not know.


"Dave Peterson" wrote in message
...
The function you're looking for is Format().

I'd use:

Cells(11, 5).Value = Left(Cells(7, 5).Value, 4) _
& Format(Mid(Cells(7, 5).Value, 5) + 1, "000")

With Mid(), you can just specify the starting position and xl's VBA will
take
the rest of the string. (Different from the =mid() worksheet function.)


Francis Hookham wrote:

Code please for incrementing text. For instance:

Text "D01-003" is in E7 and I need "D01-004" in E11

The following works but results in "D01-4" but I must maintain the "000"
format of the right three characters which need to go beyond "100"

Sub test()

Cells(11, 5) = Left(Cells(7, 5), 4) & (Right(Cells(7, 5), 3) + 1)

End Sub

Many thanks - in anticipation.

Francis Hookham


--

Dave Peterson



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
Using TEXT and &TEXT - display numbers with commas, underline text Gary Excel Discussion (Misc queries) 3 May 5th 23 03:46 AM
Text does not display in "Text boxs" and when wrapping text in a c Esteban Excel Discussion (Misc queries) 1 March 8th 07 11:59 PM
select text in cell based on text from another cell, paste the text at the begining of a thrid cell, etc... jsd219 Excel Programming 0 October 19th 06 05:04 PM
Excel VBA: Worksheet cell .Text property: 1024 bytes text len limit loyso Excel Programming 7 May 3rd 05 02:51 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 02:39 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"