jake_barnes
Board Regular
- Joined
- Sep 29, 2005
- Messages
- 55
Here's a quick and easy problem:
I'm trying to grab two-column contiguous cell groups and reverse their order (data in column A moves to column B and vice versa).
I've got this code:
Sub Reverse1()
Dim tcells As Long, mCells As Long, ix As Long, ox As Long
Dim iValue As Variant
tcells = Selection.Count
mCells = tcells / 2
For ix = 1 To mCells
iValue = Selection.Item(ix).Value
ox = tcells + 1 - ix
Selection.Item(ix).Value = Selection.Item(ox).Value
Selection.Item(ox).Value = iValue
Next ix
End Sub
But this code also reverses the row order at the same time. I just need for the cells to reverse column locations, and not row locations. Can anyone help?
Thanks in advance!
I'm trying to grab two-column contiguous cell groups and reverse their order (data in column A moves to column B and vice versa).
I've got this code:
Sub Reverse1()
Dim tcells As Long, mCells As Long, ix As Long, ox As Long
Dim iValue As Variant
tcells = Selection.Count
mCells = tcells / 2
For ix = 1 To mCells
iValue = Selection.Item(ix).Value
ox = tcells + 1 - ix
Selection.Item(ix).Value = Selection.Item(ox).Value
Selection.Item(ox).Value = iValue
Next ix
End Sub
But this code also reverses the row order at the same time. I just need for the cells to reverse column locations, and not row locations. Can anyone help?
Thanks in advance!