Changing cell References by fixed value

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,600
I have a series of formula copies from another workbook, but need all the references to be reduced by 10

for Eg for original formula which was copies is =SUM(INDEX(Sheet1!A1671:DG1671,0,104))

I need this automatically reduced by 10 for eg =SUM(INDEX(Sheet1!A1661:DG1661,0,104))

Is there a way in Excel where I can reduce a the values in the range by say 10

Your assistance will be most appreciated
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
What if you just replace, CTRL-H. change all 1671 to 1661 ?

I guess there are lots of different ones to do? If so, can you give some more info - maybe some VBA would be good?
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,600
Hi Faza

Thanks for the reply Here are some sample formula where the reference must be reduced by 10. The formulas are in col B

SUM(INDEX(Sheet1!A1674:CZ1674,0,104))
change to SUM(INDEX(Sheet1!A1664:CZ1664,0,104))

SUM(INDEX(Sheet1!$A$1531:$CZ$1531,0,104),SUM(INDEX(Sheet1!$A$1533:$CZ$1534,0,104),SUM(INDEX(Sheet1!$A$1537:$CZ$1537,0,104),SUM(INDEX(Sheet1!$A$1539:$CZ$1539,0,104),SUM(INDEX(Sheet1!$A$1541:$CZ$1541,0,104))))))

change to

SUM(INDEX(Sheet1!$A$1521:$CZ$1521,0,104),SUM(INDEX(Sheet1!$A$1523:$CZ$1524,0,104),SUM(INDEX(Sheet1!$A$1527:$CZ$1527,0,104),SUM(INDEX(Sheet1!$A$1529:$CZ$1529,0,104),SUM(INDEX(Sheet1!$A$1531:$CZ$1531,0,104))))))

Your assistance will be most appreciated

Regards

Howard
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Thanks. If I understand the pattern it helps.

Such as, every number after a $

or every number > 104

what do you think would be suitable?
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368

ADVERTISEMENT

PS

are all the numbers to change in the range 1000 to 9999. That is, a four digit number?
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Also, approximately how many worksheets & formulas need to change?
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,600

ADVERTISEMENT

Hi Faza

The range is from B1:B300. The values that must change are after $

Regards

Howard
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Hi Howard, some quick & dirty code. Range B1:B300 has formulas, numbers after $ to reduce by 10. No error checking.

:eek: Important: please back up your file before starting. :eek:

From the worksheet's tab right click and choose view code. Copy & paste code from below into the big white window on the RHS of the VBE (Visual Basic Editor). Insert cursor into the pasted code. Hit F5 to execute the code. Then return to Excel & check if it worked correctly.

Code:
Sub test()
  Dim a, b
  Dim i As Long, j As Long, k As Long
  Dim g$
  With Range("B1:B300")
    .Replace What:="=", Replacement:="'="
    ReDim a(1 To .Rows.Count, 1 To .Columns.Count)
    a = .Value
    For i = LBound(a, 1) To UBound(a, 1)
      b = Split(a(i, 1), "$")
      For j = LBound(b) To UBound(b)
        If IsNumeric(Left$(b(j), 1)) Then
          g$ = vbNullString
          k = 1
          Do While IsNumeric(Mid$(b(j), k, 1))
            g$ = g$ & Mid$(b(j), k, 1)
            k = k + 1
          Loop
          b(j) = CLng(g$) - 10 & Mid$(b(j), k)
        End If
      Next j
      a(i, 1) = Join$(b, "$")
    Next i
    .Value = a
    .Replace What:="'=", Replacement:="="
  End With
End Sub
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
You're welcome, Howard. Just thinking, if you encounter this again another approach [without VBA] is to convert the formulas to text (such as replace the "=" by "zzz=") and then temporarily use adjacent columns & text functions - such as FIND, LEFT, RIGHT, LEN - to isolate components of the formula, change as required, and then put it back together again. Regards, F
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,601
Messages
5,512,346
Members
408,887
Latest member
KPH Akron

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top