I am running Excel 2010.
I have a data set that is already organized into columns (two columns per set) - Please see the attached file by clicking on the link below!
I need to organize the columns using the numbers at the top of the row from largest to smallest. The column immediately to the right of the numbered column is part of the numbered column (they must stay together!).
Here is an example (Note: I am having problems getting the picture to view in this post, so you can download it if you wish using the following link:
https://drive.google.com/file/d/0B8ZFmctoHTEBRGtMMEU5eFo4M0k/view?usp=sharing
Here is a link to the actual file if you want to view it in full:
https://docs.google.com/spreadsheets/d/1DB_YEaZYD6ZRkIqZgVsqm3Q7aIMl2oBj-Ryu0ozTGxg/edit?usp=sharing
Details:
The top row contains the number to sort. In the instance above, 17 is the largest number. There are two other columns with the number 17 somewhere in the dataset. I need to find each one and move it and the column immediately to the right to the left so it is immediately to the right of the first column 17. Then I need to do the same thing with all column 16s, then column 15s, etc.
To add to my problem, sometimes there are only two columns with the same number, sometimes there are three and on rare occasions there is only one column with the its own number.
I hope that I have explained my problem adequately. I have tried Find statements, Find Next Statements, For...Next statements and For I statements. I am obviously doing something wrong, so I turn to the board for help. Will someone help me come up with the code to organize all the columns in order?
My data recently changed, I used to only have two sets of the same number. The code below work to first organize the columns together by number (17,17,15,15,10,10,9,9,1,1,0,0,etc.) and then organizing the second subroutine organized them in order (17,17,16,16,15,15,15,etc.). Adding the third column is what has thrown me for a loop.
Last thought before you view the code, I know my code is bloated and fat; however, I justify it be saying that I am self-taught (and still learning with the help of this board and a lot of books). If you know of a way that works with less code, I am open to learning.
Thanks for helping!
Charles (Lidsavr)
Here is the code:
I have a data set that is already organized into columns (two columns per set) - Please see the attached file by clicking on the link below!
I need to organize the columns using the numbers at the top of the row from largest to smallest. The column immediately to the right of the numbered column is part of the numbered column (they must stay together!).
Here is an example (Note: I am having problems getting the picture to view in this post, so you can download it if you wish using the following link:
https://drive.google.com/file/d/0B8ZFmctoHTEBRGtMMEU5eFo4M0k/view?usp=sharing
Here is a link to the actual file if you want to view it in full:
https://docs.google.com/spreadsheets/d/1DB_YEaZYD6ZRkIqZgVsqm3Q7aIMl2oBj-Ryu0ozTGxg/edit?usp=sharing
Details:
The top row contains the number to sort. In the instance above, 17 is the largest number. There are two other columns with the number 17 somewhere in the dataset. I need to find each one and move it and the column immediately to the right to the left so it is immediately to the right of the first column 17. Then I need to do the same thing with all column 16s, then column 15s, etc.
To add to my problem, sometimes there are only two columns with the same number, sometimes there are three and on rare occasions there is only one column with the its own number.
I hope that I have explained my problem adequately. I have tried Find statements, Find Next Statements, For...Next statements and For I statements. I am obviously doing something wrong, so I turn to the board for help. Will someone help me come up with the code to organize all the columns in order?
My data recently changed, I used to only have two sets of the same number. The code below work to first organize the columns together by number (17,17,15,15,10,10,9,9,1,1,0,0,etc.) and then organizing the second subroutine organized them in order (17,17,16,16,15,15,15,etc.). Adding the third column is what has thrown me for a loop.
Last thought before you view the code, I know my code is bloated and fat; however, I justify it be saying that I am self-taught (and still learning with the help of this board and a lot of books). If you know of a way that works with less code, I am open to learning.
Thanks for helping!
Charles (Lidsavr)
Here is the code:
Code:
Private Sub Organize_Columns()
Dim seN As Variant
Dim nxT As Variant
Dim rnG1 As Range
Range("A1").Select
' Moves the ActiveCell for columns to the right
ActiveCell.Offset(0, 4).Select
Do
Set seN = ActiveCell
If ActiveCell.Offset(0, 2).Value <> seN Then 'looks two cell to the right and determines if the value is not equal to the seN variable
Set rnG1 = ActiveCell 'sets the ActiveCell as variable rnG1
Cells.Find(What:=seN, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate 'looks for the next seN variable in the dataset
ActiveCell.EntireColumn.Select 'selects the entire column
Range(Selection, Selection.Offset(0, 1)).Select 'also selects the next column
Selection.Cut 'cuts the column
rnG1.Select 'selects the rnG1 variable
Selection.Offset(0, 2).Select 'moves the ActiveCell two columns to the right
ActiveCell.EntireColumn.Select 'selects the column, inserts the clipboard, pushing the original data to the right.
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 2).Select 'moves the ActiveCell two cells to the right to begin the next search.
Else
If ActiveCell.Offset(0, -1).Value = "" Then
Call Organize_Columns2
End If
ActiveCell.Offset(0, 4).Select
End If
Loop Until ActiveCell.Offset(3, 0).Value = "Run_ID" 'Loops the subroutine until conditions are met.
Call Organize_Columns2
End
End Sub
Private Sub Organize_Columns2()
Dim rng2 As Range
Dim rng3 As Range
Dim mX1 As Variant
Dim mX2 As Variant
Dim mX3 As Variant
Dim mX4 As Variant
Dim mX5 As Variant
Dim mX6 As Variant
Dim mX7 As Variant
Dim mX8 As Variant
Dim mX9 As Variant
Dim mX10 As Variant
Dim mX11 As Variant
Dim mX12 As Variant
Dim mX13 As Variant
Dim mX14 As Variant
Dim mX15 As Variant
Sheets("DataLog").Select
' Sets gives variables values (numbers).
Range("E1:CA1").Select
Set rng2 = Selection
mX1 = WorksheetFunction.Max(rng2)
mX2 = mX1 - 1
mX3 = mX1 - 2
mX4 = mX1 - 3
mX5 = mX1 - 4
mX6 = mX1 - 5
mX7 = mX1 - 6
mX8 = mX1 - 7
mX9 = mX1 - 8
mX10 = mX1 - 9
mX11 = mX1 - 10
mX12 = mX1 - 11
mX13 = mX1 - 12
mX14 = mX1 - 13
mX15 = mX1 - 14
mX16 = mX1 - 15
mX17 = mX1 - 16
On Error Resume Next
' Starts organizing columns so they are in order starting with the largest number
Range("E1").Select
Set rng3 = Selection
If mX1 = rng3.Value Then
If mX1 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX1, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
ActiveCell.Select
If ActiveCell.Value = mX1 Then
ActiveCell.Offset(0, 4).Select
End If
End If
Set rng3 = Selection
If mX2 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX2 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX2, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX2 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX1, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX3
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX2 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX3:
Set rng3 = Selection
If mX3 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX3 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX3, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX3 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX2, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX4
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX3 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX4:
Set rng3 = Selection
If mX4 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX4 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX4, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX4 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX3, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX5
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX4 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX5:
Set rng3 = Selection
If mX5 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX5 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX5, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX5 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX4, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX6
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX5 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX6:
Set rng3 = Selection
If mX6 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX6 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX6, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX6 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX5, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX7
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX6 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX7:
Set rng3 = Selection
If mX7 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX7 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX7, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX7 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX6, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX8
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX7 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX8:
Set rng3 = Selection
If mX8 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX8 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX8, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX8 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX7, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX9
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX8 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX9:
Set rng3 = Selection
If mX9 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX9 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX9, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX9 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX8, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX10
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX9 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX10:
Set rng3 = Selection
If mX10 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX10 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX10, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX10 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX9, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX11
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX10 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX11:
Set rng3 = Selection
If mX11 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX11 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX11, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX11 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX10, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX12
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX11 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX12:
Set rng3 = Selection
If mX12 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX12 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX12, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX12 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX11, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX13
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX12 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX13:
Set rng3 = Selection
If mX13 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX13 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX13, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX13 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX12, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX14
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX13 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX14:
Set rng3 = Selection
If mX14 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX14 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX14, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX14 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX13, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX15
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX14 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX15:
Set rng3 = Selection
If mX15 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX15 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX15, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX15 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX14, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX16
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX15 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX16:
Set rng3 = Selection
If mX16 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX16 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX16, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX16 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX15, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
GoTo SECT_MX17
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX16 Then
ActiveCell.Offset(0, 4).Select
End If
End If
SECT_MX17:
Set rng3 = Selection
If mX17 < 0 Then
Application.CutCopyMode = False
Range("A1").Select
On Error GoTo 0
End
End If
If mX17 = rng3.Value Then
ActiveCell.Offset(0, 4).Select
Else
Cells.Find(What:=mX17, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If ActiveCell.Offset(0, 2) <> mX17 Then
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 1)).Select
Selection.Copy
Selection.Offset(0, 2).Select
Selection.Insert Shift:=xlToRight
Application.CutCopyMode = False
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
Range("E1").Select
Cells.Find(What:=mX16, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Selection.Insert Shift:=xlToRight
ActiveCell.Offset(0, 4).Select
End
End If
ActiveCell.EntireColumn.Select
Range(Selection, Selection.Offset(0, 3)).Select
Selection.Cut
rng3.Select
Selection.Insert Shift:=xlToRight
If ActiveCell.Value = mX17 Then
ActiveCell.Offset(0, 4).Select
End If
End If
On Error GoTo 0
End
End Sub