I have some data that gets pulled on a weekly basis and looks terrible, so I have a formatting sheet that puts the data in a more friendly format that's readable.
Unfortunately management decided to add a column in the raw data, which throws off all of my cell references by 1 column. Here's my current code in the cells:
=IF(([SPREADSHEETREF.xlsx]Raw1!AD3)=0,"-",([SPREADSHEETREF.xlsx]Raw1!AD3))
I need to "add" one column to the current references. So that in the above example, it would replaces AD3
with AE3
.
I was thinking of using WorksheetFunction.Replace( old_text, start, number_of_chars, new_text )
, but I'm not sure it would work in this case.
I can't seem to figure out how to make the new_text
some type of value addition, so that it's like OldValue + 1 = AE
. The columns being referenced are all over the place, so I need the flexibility of using like a +1 formula to do this.
The following function will shift AD1 to AE1:
Function ShiftAddress(CellAddress As String, Optional shift As Long = 1) As String
Dim R As Range
Set R = Range(CellAddress)
ShiftAddress = R.Offset(0, shift).Address(False, False)
End Function
ShiftAddress("AD1") returns "AE1". ShiftAddress("AD1",2) returns "AF1", etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.