View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Prohock Prohock is offline
external usenet poster
 
Posts: 12
Default Command Button to Swap Cells

I have a button that has the following VB connected with it. The function
will only swap the values of two cells and not the formats. I would like the
formats to be swapped as well. Any ideas?

Private Sub CommandButton1_Click()
Dim vTemp As Variant
With Selection
If .Count < 2 Then
MsgBox "2 cells only."
Else
If .Areas.Count = 2 Then
vTemp = .Areas(1).Cells.Value
.Areas(1).Cells.Value = .Areas(2).Cells.Value
.Areas(2).Cells.Value = vTemp

Else
vTemp = .Cells(1).Value
.Cells(1).Value = .Cells(2).Value
.Cells(2).Value = vTemp
End If
End If
End With
End Sub