I am trying to do two separate sorting of my data according to the dynamic range it falls under.
It is a product order list.
The list has hundreds of products, but a single order may only have x amount of products.
I need to sort the ordered products to the top of the list, and then sort the ordered products to the specifications I require.
There are 2 separate sort functions;
Select the entire range according to values entered in column E, sort by column E.
Select the entire range according to values entered in column E, sort by column C then B.
Thank you :)
I have tried to record a macro and edit it.
No matter what forum/thread solution I have tried, it doesn't give me the correct results.
This is the code of the recorded macro:
Sub SortOrder()
'
' SortOrder Macro
'
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Customer Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Customer Order").Sort.SortFields.Add2 Key:=Range( _
"E5:E240"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Customer Order").Sort
.SetRange Range("A4:E240")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("E4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToLeft)).Select
ActiveWorkbook.Worksheets("Customer Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Customer Order").Sort.SortFields.Add2 Key:=Range( _
"C5:C95"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Customer Order").Sort.SortFields.Add2 Key:=Range( _
"B5:B95"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Customer Order").Sort
.SetRange Range("A4:E95")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
I have a VBA which works fine (Takes time to execute) in my excel 365 but does not work in excel 2016
I am importing excel as SHEET (2) and sorting first and second sheet respective columns and copying second sheet to first after last used column.
ActiveWorkbook.Sheets("SHEET").Select
Range("C1").Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveWorkbook.Worksheets("SHEET").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("SHEET").AutoFilter.Sort.SortFields.Add2 Key:=Range _
("C1:C50000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("SHEET").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("SHEET (2)").Select
Range("A1").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("SHEET (2)").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("SHEET (2)").AutoFilter.Sort.SortFields.Add2 Key:= _
Range("A1:A50000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("SHEET (2)").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Sheets("SHEET").Select
Sheets("SHEET (2)").Select ' origin sheet
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
X = Selection.Columns.count ' get number of columns
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("SHEET").Select ' destination sheet
Range("AH1").Select
ActiveSheet.Paste
I have two problems
code get stuck with runtime error 438 at line of in excel 2016
ActiveWorkbook.Worksheets("SHEET").AutoFilter.Sort.SortFields.Add2 Key:=Range _
("C1:C50000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
If I have more than 10000 rows its runs very slowly.
can any one guide me with this please?
I can do some basic sortinng using vba however i cannot get things to work when i want to make it dynamic...
what i have done now is set a hard stop at 10k, however the workbooks i need to sort change rapidly in size.
what would be the best approach and why?
i have tried to set the "Range" to Range("a1:B" & lastrow), respectively for each select however this seems to hang and not execute the macro.
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"A1:BZ1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Rapportage").Sort
.SetRange Range("A1:BZ9999")
.Header = xlYes
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Application.CutCopyMode = False
Range("q3", Range("q5 : q9999")).FormulaR1C1 = "=RC[1]+RC[2]"
Rows("5:9999").Select
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"B5:B9999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"C5:C9999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"F5:F9999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"E5:E9999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Rapportage").Sort.SortFields.Add2 Key:=Range( _
"I5:I9999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Rapportage").Sort
.SetRange Range("A5:BZ9999")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With```
I think your code should look somewhat like the procedure below. Note that the Key defines the column to be sorted on. It's specified by a single cell in it, usually in the first row but I chose the fifth because the first row is excluded from your range - not that VBA or Excel would take offence.
Sub TestSort()
' 041
Dim Cell As Range
Dim SortRng As Range
With ActiveWorkbook.Worksheets("Rapportage")
Set Cell = .Cells(5, 2)
With .Sort.SortFields
.Clear
.Add Key:=Cell, SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Cell.Offset(, 1), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Cell.Offset(, 4), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Cell.Offset(, 3), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Add Key:=Cell.Offset(, 7), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
End With
Set SortRng = .Range(.Cells(5, "A"), _
.Cells(.Rows.Count, "A").End(xlUp).Offset(, 77))
With .Sort
.SetRange SortRng
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
Specifying the column to sort on is different from specifying the range to be sorted. That enters the code only after the keys have all been set and the actual sorting process is initiated.
I am struggling to cover everything I need to do in one macro - I asked a similar question here a few hours ago and was answered however unfortunately I needed to add a few functions to my macro so I had to modify it slightly and now I require a tiny tweak that I can't get to work
Sub BoBTEST()
Dim c As Range
For Each c In Range("A1:BR1").Cells
If c.Value = "Plate Name (barcode)" Or c.Value = "Measurement Date" Or c.Value = "Measurement profile" Or c.Value = "pH" Or c.Value = "Count" Or c.Value <= 30 Then
c.EntireColumn.Hidden = False
Else: c.EntireColumn.Hidden = True
End If
Next c
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range( _
"AF2:AF1761"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range( _
"AN2:AN1761"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range( _
"J2:J1761"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:BR1761")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1:BR1761").Select
Range("AT9").Activate
Selection.AutoFilter
Selection.AutoFilter
ActiveSheet.Range("$A$1:$BR$1761").AutoFilter Field:=32, Criteria1:= _
"=Shear Rated(gamma)/dt = 4 1/s", Operator:=xlOr, Criteria2:="="
ActiveSheet.Range("$A$1:$BR$1761").AutoFilter Field:=40, Criteria1:= _
"=Viscosity", Operator:=xlOr, Criteria2:="="
End Sub
Basically what it does so far is takes data which is exported from a robot, hides the columns that I don't want and filters the values that I don't want
The problem is that these columns are dynamic and occasionally move around - the macro is able to hide all of the columns I don't want however I'm struggling to make it search for these columns and then filter, right now it is using a recording I did so it selects e.g. column J and then filters
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range( _
"J2:J1761"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
However it may not be on column J it might be at K as occasionally more columns are entered when exporting data
Is there any way to tweak the macro to make it so the auto-filter part actually searches for column headers as opposed to doing these functions on e.g. "J2:J2000" etc.
Thanks a lot apologies that it is long winded I wanted to cover everything
I am new VBA user trying to assemble a very basic trade reconciliation template. I seem to have the majority done, but I cant seem to work out the sorting behavior "such that" all stocks that are unmatched shown on separate row lines. As you can see I was able to get the sorting to work for the main portion of items that matched, but all the unmatched items just get pushed to the bottom. That is fine, but really they should be on separate rows to show visually that each line item is separately unmatched.
This is as far as I could get with my code. Separating out the rows with all unmatched items where say the stock name (A4 vs. H4) and also the quantity (E4 vs L4) are not matching all should be getting moved to their own line item - to visually confirm for the end reader there is a unmatch.
Sub Sample_Trade_Recon()
Application.ScreenUpdating = False
' Tab 1 & Tab 2 Raw data pasted in. Do a prelim sort of the actual columns
you want compare on the summary sheet'
Sheets("QT").Select Range("A3:G300").Select
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("A3:A300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("B3:B300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("C3:C300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("D3:D300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("E3:E300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("F3:F300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("G3:G300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With
ActiveWorkbook.Worksheets("QT").Sort .SetRange Range("A3:G300") .Header =
xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod =
xlPinYin .Apply End With
Sheets("SSC").Select
Range("A3:G300").Select
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("A3:A300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("B3:B300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("C3:C300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("D3:D300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("E3:E300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("F3:F300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("G3:G300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SSC").Sort
.SetRange Range("A3:G300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' Tab 1 Raw data columns you want compared '
Sheets("QT").Select
Range("A3:A40").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("B3:B40").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("C3:C40").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("QT").Select
Range("D3:D40").Select
Selection.Copy
Sheets("Recon").Select
Range("D4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("QT").Select
Range("E3:E40").Select
Selection.Copy
Sheets("Recon").Select
Range("E4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("F3:F40").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("F4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("G3:G40").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("G4").Select
Selection.PasteSpecial Paste:=xlPasteValues
' Tab 2 Raw data columns you want compared '
Sheets("SSC").Select
Range("A3:A45").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("H4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("B3:B45").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("I4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("C3:C45").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("J4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("SSC").Select
Range("D3:D45").Select
Selection.Copy
Sheets("Recon").Select
Range("K4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("SSC").Select
Range("E3:E45").Select
Selection.Copy
Sheets("Recon").Select
Range("L4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("F3:F45").Select
Selection.Copy
Sheets("Recon").Select
Range("M4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("G3:G45").Select
Selection.Copy
Sheets("Recon").Select
Range("N4").Select
Selection.PasteSpecial Paste:=xlPasteValues
MsgBox ("Recon is assembled; please comment on all differences !")
End Sub
So looks like im getting very close to the desired behavior. Only issue is its happening only once ?
Please see the updated code and let me know if anyone can assist with why its not repeating when the skip row is showing.
enter image description here
Sub Sample_Trade_Recon()
Application.ScreenUpdating = False
' Tab 1 & Tab 2 Raw data pasted in. Do a prelim sort of the actual columns
you want compare on the summary sheet'
Sheets("QT").Select
Range("A3:G300").Select
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("A3:A300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("B3:B300"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("C3:C300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("D3:D300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("E3:E300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("F3:F300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("QT").Sort.SortFields.Add Key:=Range("G3:G300"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("QT").Sort
.SetRange Range("A3:G300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("SSC").Select
Range("A3:G300").Select
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("A3:A300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("B3:B300"),
_
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("C3:C300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("D3:D300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("E3:E300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("F3:F300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("SSC").Sort.SortFields.Add Key:=Range("G3:G300"),
_
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("SSC").Sort
.SetRange Range("A3:G300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' Tab 1 Raw data columns you want compared '
Sheets("QT").Select
Range("A3:A300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("B3:B300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("C3:C300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("QT").Select
Range("D3:D300").Select
Selection.Copy
Sheets("Recon").Select
Range("D4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("QT").Select
Range("E3:E300").Select
Selection.Copy
Sheets("Recon").Select
Range("E4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("F3:F300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("F4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QT").Select
Range("G3:G300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("G4").Select
Selection.PasteSpecial Paste:=xlPasteValues
' Tab 2 Raw data columns you want compared '
Sheets("SSC").Select
Range("A3:A300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("H4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("B3:B300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("I4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("C3:C300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Recon").Select
Range("J4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("SSC").Select
Range("D3:D300").Select
Selection.Copy
Sheets("Recon").Select
Range("K4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Selection.NumberFormat = "m/d/yyyy"
Sheets("SSC").Select
Range("E3:E300").Select
Selection.Copy
Sheets("Recon").Select
Range("L4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("F3:F300").Select
Selection.Copy
Sheets("Recon").Select
Range("M4").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("SSC").Select
Range("G3:G300").Select
Selection.Copy
Sheets("Recon").Select
Range("N4").Select
Selection.PasteSpecial Paste:=xlPasteValues
'Dynamic Sorting based on column total lengths'
Dim lastA, lastB, shortCol, rw As Integer
'Determine short column so we know when to stop
lastA = WorksheetFunction.CountA(Range("A:A"))
lastB = WorksheetFunction.CountA(Range("H:H"))
If lastA > lastB Then _
shortCol = 2 Else shortCol = 1
'Set First Check Row
rw = 4
nxtChk:
'Check Column A against Column H, Row by Row
'Insert cell at non-matching data
If Cells(rw, 26) <> "Keep" And shortCol = 2 Then
Cells(rw, 8).Insert shift:=xlDown
Cells(rw, 9).Insert shift:=xlDown
Cells(rw, 10).Insert shift:=xlDown
Cells(rw, 11).Insert shift:=xlDown
Cells(rw, 12).Insert shift:=xlDown
Cells(rw, 13).Insert shift:=xlDown
Cells(rw, 14).Insert shift:=xlDown
Refresh all formulas in difference column so excel knows where to insert
the skip row (based on formulas)'
Range("O4:Z4").Select
Selection.AutoFill Destination:=Range("O4:Z300")
Else
If Cells(rw, 26) <> "Keep" And shortCol = 1 Then
Cells(rw, 1).Insert shift:=xlDown
Cells(rw, 2).Insert shift:=xlDown
Cells(rw, 3).Insert shift:=xlDown
Cells(rw, 4).Insert shift:=xlDown
Cells(rw, 5).Insert shift:=xlDown
Cells(rw, 6).Insert shift:=xlDown
Cells(rw, 7).Insert shift:=xlDown
'Refresh all formulas in difference column so excel knows where to insert
the skip row (based on formulas)'
Range("O4:Z4").Select
Selection.AutoFill Destination:=Range("O4:Z300")
End If
'If there is nothing left to check in the skiprow column , we're done
If Cells(rw, 26) = " " Then Exit Sub
'If not, increment Row counter and loop
rw = rw + 1
GoTo nxtChk
End If
Range("O4:Z4").Select
Selection.AutoFill Destination:=Range("O4:Z300")
Application.ScreenUpdating = True
'Operations Team notices to review data presentation'
MsgBox ("Please insert comments into Column AA for all differences !")
MsgBox ("NOTE: If identifer data sorting is off slightly; then please fix by
repasting the data grids on either side up/down a row as needed to realign
properly. This often happens when Identifiers Repeat ")
End Sub