1

我在 Excel 中工作。下面的代码是 A 列中的 4 行。在 BI 列中有一系列从 0 开始的整数。我希望 B 列中的值替换“?” 在 A 列中。我在 Google 上搜索了 Excel 中的高级复制和粘贴以及查找和替换技术,但结果只是告诉我使用特殊粘贴。我试图在查找和替换工具中引用 B 列,但无法这样做。任何帮助将不胜感激。

"<class type=""sItemManager::cITEM_PARAM_DATA"">
<s16 name=""data.mNum"" value=""900""/>
<s16 name=""data.mItemNo"" value=""?""/>
<u32 name=""data.mFlag"" value=""1""/>
<u16 name=""data.mChgNum"" value=""0""/>
<u16 name=""data.mDay1"" value=""0""/>
<u16 name=""data.mDay2"" value=""0""/>
<u16 name=""data.mDay3"" value=""0""/>
<s8 name=""data.mMutationPool"" value=""0""/>
<s8 name=""data.mOwnerId"" value=""4""/>
<u32 name=""data.mKey"" value=""0""/>
</class>"
"<class type=""sItemManager::cITEM_PARAM_DATA"">
<s16 name=""data.mNum"" value=""900""/>
<s16 name=""data.mItemNo"" value=""?""/>
<u32 name=""data.mFlag"" value=""1""/>
<u16 name=""data.mChgNum"" value=""0""/>
<u16 name=""data.mDay1"" value=""0""/>
<u16 name=""data.mDay2"" value=""0""/>
<u16 name=""data.mDay3"" value=""0""/>
<s8 name=""data.mMutationPool"" value=""0""/>
<s8 name=""data.mOwnerId"" value=""4""/>
<u32 name=""data.mKey"" value=""0""/>
</class>"
"<class type=""sItemManager::cITEM_PARAM_DATA"">
<s16 name=""data.mNum"" value=""900""/>
<s16 name=""data.mItemNo"" value=""?""/>
<u32 name=""data.mFlag"" value=""1""/>
<u16 name=""data.mChgNum"" value=""0""/>
<u16 name=""data.mDay1"" value=""0""/>
<u16 name=""data.mDay2"" value=""0""/>
<u16 name=""data.mDay3"" value=""0""/>
<s8 name=""data.mMutationPool"" value=""0""/>
<s8 name=""data.mOwnerId"" value=""4""/>
<u32 name=""data.mKey"" value=""0""/>
</class>"
"<class type=""sItemManager::cITEM_PARAM_DATA"">
<s16 name=""data.mNum"" value=""900""/>
<s16 name=""data.mItemNo"" value=""?""/>
<u32 name=""data.mFlag"" value=""1""/>
<u16 name=""data.mChgNum"" value=""0""/>
<u16 name=""data.mDay1"" value=""0""/>
<u16 name=""data.mDay2"" value=""0""/>
<u16 name=""data.mDay3"" value=""0""/>
<s8 name=""data.mMutationPool"" value=""0""/>
<s8 name=""data.mOwnerId"" value=""4""/>
<u32 name=""data.mKey"" value=""0""/>
</class>"
4

1 回答 1

0

尝试以下操作(您可以删除一些为调试目的而包含的变量):

Sub test()
    Dim rng As Range, cl As Range
    Set rng = Range("A1:A4")
    Dim cl1 As Range, cl2 As Range
    For Each cl1 In rng
      Set cl2 = cl1.Offset(0, 1)
      Dim ival As Integer
      ival = cl2.Value
      Dim res As String
      res = Application.WorksheetFunction.Substitute(cl1.Text, "?", Trim(Str(ival)))
      cl1 = res
    Next cl1
End Sub

或这个

Sub test()
    Dim rng As Range, cl As Range
    Set rng = Range("A1:A4")
    Dim cl1 As Range, cl2 As Range
    For Each cl1 In rng
      Set cl2 = cl1.Offset(0, 1)
      Dim ival As Integer
      ival = cl2.Value
      cl1.Replace What:="~?", Replacement:=Str(ival)
    Next cl1
End Sub
于 2013-11-12T04:39:35.753 回答