Macro to increase a cell reference by 11
Solved/Closed
SLKG
Posts
6
Registration date
Friday April 16, 2010
Status
Member
Last seen
April 27, 2010
-
Apr 26, 2010 at 04:41 PM
YaneyYan - Mar 7, 2017 at 03:53 PM
YaneyYan - Mar 7, 2017 at 03:53 PM
Related:
- Macro to increase a cell reference by 11
- Fc 24 free download for pc windows 11 - Download - Sports
- Samsung volume increase code - Guide
- Ms access free download for windows 11 - Download - Databases
- Net send windows 11 - Guide
- Gta 5 download apk pc windows 11 - Download - Action and adventure
2 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 26, 2010 at 09:27 PM
Apr 26, 2010 at 09:27 PM
Assuming that the cell in which the formula is C18 (change the code to reflect the right cell)
Sub Auto_Open()
Dim currentRow As String
Dim sTemp As String
sTemp = Range("C18").Formula
Do While (IsNumeric(Right(sTemp, 1)))
currentRow = Right(sTemp, 1) & currentRow
sTemp = Mid(sTemp, 1, Len(sTemp) - 1)
Loop
currentRow = CLng(currentRow) + 11
Range("C18").Formula = sTemp & currentRow
End Sub
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 27, 2010 at 12:14 PM
Apr 27, 2010 at 12:14 PM
Sub Auto_Open()
Dim targetCells As Variant
Dim targetCell As Variant
targetCells = Array("C18", "C20", "C22", "C24", "C26", "C28", "C30", "C32", "C34", "C36", "C38")
For Each targetCell In targetCells
Call increaseAddress(CStr(targetCell), 11)
Next
End Sub
Sub increaseAddress(targetRange As String, increaseBy As Integer)
Dim currentRow As String
Dim sTemp As String
sTemp = Range(targetRange).Formula
currentRow = ""
If sTemp <> "" Then
Do While (IsNumeric(Right(sTemp, 1)))
currentRow = Right(sTemp, 1) & currentRow
sTemp = Mid(sTemp, 1, Len(sTemp) - 1)
Loop
currentRow = CLng(currentRow) + increaseBy
Range(targetRange).Formula = sTemp & currentRow
End If
End Sub
SLKG
Posts
6
Registration date
Friday April 16, 2010
Status
Member
Last seen
April 27, 2010
Apr 27, 2010 at 05:48 PM
Apr 27, 2010 at 05:48 PM
Thank you! As ever the genius! Works a treat!
SLKG
SLKG
Apr 26, 2010 at 10:07 PM
that works great. There are actually more rows than just C18 to change. How would I update it to do the same to rows C20, C22, C24, C26, C28, C30, C32, C34, C36, C38 without duplicating the whole formula?
SLKG
Mar 7, 2017 at 03:53 PM