Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
macro to increment/decrement values in selected cells | Excel Programming | |||
cell math to decrement/increment a cell | Excel Worksheet Functions | |||
How do I increment or decrement values in a column? | New Users to Excel | |||
Provide increment and decrement buttons on toolbar line | Excel Programming | |||
Spin Button to increment or decrement the date in cell A1 | Excel Programming |