Originally Posted by
mbarron
Make sure your B2:M13 range is formatted as Text otherwise the changed cells will become dates. The following will switch the numbers around when you click within the table. If you click outside of the table the last selected column will be reversed. If you click in the same column, nothing happens to the numbers (they do change, but then are changed back)
Assign the following to the the selection change event (right click on the tab and choose View Code..., then paste the following macro):
[vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static lCol As Integer, cCell As Range
If Not Intersect(Target, Range("B2:M13")) Is Nothing Then
Application.EnableEvents = False
For Each cCell In Range(Cells(2, Target.Column), Cells(13, Target.Column))
cCell.Value = CStr(Right(cCell, 1) & "-" & Left(cCell, 1))
Next
If lCol <> 0 Then
For Each cCell In Range(Cells(2, lCol), Cells(13, lCol))
cCell.Value = CStr(Right(cCell, 1) & "-" & Left(cCell, 1))
Next
End If
lCol = Target.Column
Application.EnableEvents = True
Else
Application.EnableEvents = False
If lCol <> 0 Then
For Each cCell In Range(Cells(2, lCol), Cells(13, lCol))
cCell.Value = CStr(Right(cCell, 1) & "-" & Left(cCell, 1))
Next
lCol = 0
End If
Application.EnableEvents = True
End If
End Sub
[/vba]