I have put together this bit of code to help speed up our electrical interconnect reports and it works great except that it only works on a single selection of several continues rows (click row 2, Shift+ Click row 5). If I attempt to use Ctrl+Click and select several different rows the code falls apart.
Ideally I would like to be able to make any number of Shift+Click and Ctrl+Click Selections and then run my code.
I think I only need to know the number of rows selected.
the purpose of this code is to flip the rows selected by the user so that what ever data was on the right hand would be moved to the left hand. The attached picture shows that some of the data that I am working with.
Capture.PNG
All of the data is flipped about column I. The data to be flipped is located between columns C & O, this range has also been formatted as text.
Can anyone help? I have been trying but can't find the answer.
Thanks in advance.
Sub FlipRows()
'
' FlipRows Macro
' Flip selected signal(s)
'
'User selects selects the desired rows an then they go to dialog-special-constants selects
'the range of cells between, and including, columns "C" and "O" that are with in the user selected rows.
Dim C As Long
Dim I As Long, J As Long
Dim r As Long
Dim NewData As Variant
Dim OldData As Variant
Dim rng As Range
Dim test
Dim test2
'''''Check if there is data
If Range("A1").Value <> "CONDUIT NUM" Then
Exit Sub
End If
'''''Flip selected rows about the WIRENO column !!!!At this time only one continues selection can be flipped more then one selection will cause error!!!!
Selection.SpecialCells(xlCellTypeConstants, 2).Select
Set rng = Selection
OldData = rng.Value 'the values of the selected range is stored in OldData
ReDim NewData(1 To rng.Rows.Count, 1 To rng.Columns.Count) 'Arrey for number of rows(value changes) and number of columns (value should always be 13) the user selected
For I = 1 To UBound(OldData, 1) 'number of rows to process
r = r + 1
For J = UBound(OldData, 2) To 1 Step -1 'number of columns to proces
C = C + 1
NewData(r, C) = OldData(I, J) 'current row being processed from OldData. flips cell values about column "I" staring with the right side moving moving to the left. The values new location is stored in NewData.
Next J
C = 0
Next I
rng.Value = NewData 'the new value locations are applied to the current selection
End Sub
Bookmarks