2017-07-24 361 views
-2

这仅仅是一个小小的基本疑问,我被卡住了。我们如何使用VBA交换单元格内的值?使用VBA在excel中对单元格内的值进行交换使用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 

请如果有人可以帮助

+1

到目前为止你做了什么 - 向我们展示你的尝试,以便我们能够帮助你。 – FunThomas

回答

0

选择一个单元格:

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

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

0
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。谢谢。

相关问题