Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Increment/decrement a number in text cell

I have cells with text and numbers in XX#-XXX or XX#-XXX# and I would like to
increment or decrement just the number(s) in the cells selected with a macro.
Thank you for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Increment/decrement a number in text cell

I forgot there is a third format as well XX#-XXXX I don't know if that makes
any diffrence

"PhilosophersSage" wrote:

I have cells with text and numbers in XX#-XXX or XX#-XXX# and I would like to
increment or decrement just the number(s) in the cells selected with a macro.
Thank you for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Increment/decrement a number in text cell

Give this macro a try...

Sub IncrementNumbers()
Dim X As Long, Z As Long, Cell As Range, Numbers() As String
For Each Cell In Selection
Numbers = Split(Cell.Value, "-")
For X = 0 To 1
If Numbers(X) Like "*#" Then
For Z = Len(Numbers(X)) To 1 Step -1
If Mid(Numbers(X), Z, 1) Like "[!0-9]" Then
Numbers(X) = Left(Numbers(X), Z) & (1 + Mid(Numbers(X), Z + 1))
Exit For
End If
Next
End If
Next
Cell.Value = Numbers(0) & "-" & Numbers(1)
Next
End Sub

--
Rick (MVP - Excel)


"PhilosophersSage" wrote in
message ...
I forgot there is a third format as well XX#-XXXX I don't know if that
makes
any diffrence

"PhilosophersSage" wrote:

I have cells with text and numbers in XX#-XXX or XX#-XXX# and I would
like to
increment or decrement just the number(s) in the cells selected with a
macro.
Thank you for your help!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Increment/decrement a number in text cell

With values like:
12#-345 in your cells, select the cells and run:

Sub Inkrement()
For Each r In Selection
v = r.Value
s = Split(r, "#-")
s(0) = s(0) + 1
s(1) = s(1) + 1
r.Value = Join(s, "#-")
Next
End Sub

--
Gary''s Student - gsnu200908


"PhilosophersSage" wrote:

I have cells with text and numbers in XX#-XXX or XX#-XXX# and I would like to
increment or decrement just the number(s) in the cells selected with a macro.
Thank you for your help!

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
macro to increment/decrement values in selected cells Sunny Excel Programming 2 March 28th 07 06:26 AM
cell math to decrement/increment a cell BUFFETT Excel Worksheet Functions 1 June 16th 06 08:37 PM
How do I increment or decrement values in a column? OldKenGoat New Users to Excel 3 January 6th 05 01:05 AM
Provide increment and decrement buttons on toolbar line ExcelStudent Excel Programming 1 October 3rd 04 07:39 AM
Spin Button to increment or decrement the date in cell A1 Pal Excel Programming 5 August 4th 03 11:43 AM


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

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"