简体   繁体   English

复杂的字符串替换

[英]Complicated string replace

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. 不幸的是,管理层决定在原始数据中添加一列,这使我所有的单元格引用都减少了1列。 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 . 因此,在上面的示例中,它将用AE3替换AD3

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. 我正在考虑使用WorksheetFunction.Replace( old_text, start, number_of_chars, new_text ) ,但是我不确定在这种情况下是否可以使用。

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 . 我似乎无法弄清楚如何使new_text某种类型的增值,因此就像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. 被引用的列无处不在,所以我需要灵活地使用+1公式来执行此操作。

The following function will shift AD1 to AE1: 以下功能会将AD1转换为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”)返回“ AE1”。 ShiftAddress("AD1",2) returns "AF1", etc. ShiftAddress(“ AD1”,2)返回“ AF1”,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM