【问题标题】:Swapping of values within a cell in excel using VBA使用VBA在excel中的单元格内交换值
【发布时间】:2017-07-24 14:38:58
【问题描述】:

这只是我卡在哪里的一个小基本疑问。我们如何使用 VBA 交换单元格内的值?

For Example
If the value in the cell is 0080 I want it to be swapped to 8000
or if the value is 1567 it should be swapped to 6715

如果有人可以帮忙,请帮忙

【问题讨论】:

  • 到目前为止您做了什么 - 向我们展示您的尝试,以便我们为您提供帮助。

标签: excel vba cell


【解决方案1】:

选择一个单元格并:

Sub swap()
    With ActiveCell
        .Value = Right(.Value, 2) & Left(.Value, 2)
    End With
End Sub

【讨论】:

    【解决方案2】:

    WS.Range("A5").Value = Right$(WS.Range("A5").Value, 2) & left$(WS.Range("A5").Value, 2)

    【讨论】:

      【解决方案3】:
      Sub Replace()
          ActiveCell.Replace What:="0080^t", Replacement:="8000^t", LookAt:=xlPart, _
              SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
              ReplaceFormat:=False
          Cells.Replace What:="0080", Replacement:="8000", LookAt:=xlWhole, SearchOrder _
              :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
      End Sub
      

      它适用于我的 Excel。谢谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多