View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
mdmackillop[_27_] mdmackillop[_27_] is offline
external usenet poster
 
Posts: 1
Default Incrementing complex data


You're not totally clear in your requirements, so here are 3 simple
options to play with

Code:
--------------------
'Increase last number by 1 in all cells
Sub Incr1()
Dim c As Range, t As Variant
For Each c In Selection
If c.Column = 3 Then
If InStr(1, c, "x") 0 Then
t = Split(c, "x")
c.Value = t(0) & "x" & t(1) + 1
End If
End If
Next
End Sub

'Changee last number in all cells
Sub Incr2()
Dim c As Range, t As Variant
For Each c In Selection
If c.Column = 3 Then
If InStr(1, c, "x") 0 Then
t = Split(c, "x")
c.Value = t(0) & "x" & InputBox("Change value " & t(1), "Increment")
End If
End If
Next
End Sub


'Use row number to increment values
Sub Incr3()
Dim c As Range, t As Variant, Rw As Long
'Get number of first row of selection
Rw = Selection(1).Row
For Each c In Selection
If c.Column = 3 Then
If InStr(1, c, "x") 0 Then
t = Split(c, "x")
'Increment by difference in row numbers
c.Value = t(0) & "x" & t(1) + c.Row - Rw
End If
End If
Next
End Sub


--------------------


--
mdmackillop
------------------------------------------------------------------------
mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=64367