ststern45
Well-known Member
- Joined
- Sep 17, 2005
- Messages
- 974
- Office Version
- 365
- 2010
- Platform
- Windows
I have a list of 324 sets of data in columns that are identical in size
I tried using Record Macro then changing a few lines of code but received errors on a few lines of code.
The new lines of code are for adjusted cell columns,
Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value)
The code below is the Record Macro
Sub SortDelete()
Range("BL2:BN326").Select
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _
"BN2:BN326"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("FLRLSets").Sort
.SetRange Range("BL2:BN326")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("BL2:BN131").Select
Selection.Delete Shift:=xlUp
Range("AXQ1").Select
End Sub
===========================================================================
This is the code I tried to use:
Sub SortDelete1()
Dim aRng As String
aRng = Sheets("FLRLSets").Range("AXO1").Value
With ActiveSheet
For Each cll In .Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value).Cells
.Range("AXO4").Value = cll.Value
SortDelete2
Next cll
End With
End Sub
Sub SortDelete2()
Dim aRng As String
Dim bRng As String
Application.ScreenUpdating = False
aRng = Sheets("FLRLSets").Range("AXO5").Value
bRng = Sheets("FLRLSets").Range("AXO7").Value
Sheets("FLRLSets").Select
Range(aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value).Select
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _
"aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ "this line gives an error
xlSortNormal
With ActiveWorkbook.Worksheets("FLRLSets").Sort
.SetRange Range("AXM2").Value & ":" & bRng & Range("AXM3").Value") 'this line of code gives an error
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply 'This line gives an error
End With
Range(aRng & Range("AXO8").Value & ":" & bRng & Range("AXO9").Value).Select
Selection.Delete Shift:=xlUp
Sheets("FLRLSets").Select
Range("AXQ1").Select
Application.ScreenUpdating = True
End Sub
I tried using Record Macro then changing a few lines of code but received errors on a few lines of code.
The new lines of code are for adjusted cell columns,
Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value)
The code below is the Record Macro
Sub SortDelete()
Range("BL2:BN326").Select
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _
"BN2:BN326"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("FLRLSets").Sort
.SetRange Range("BL2:BN326")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("BL2:BN131").Select
Selection.Delete Shift:=xlUp
Range("AXQ1").Select
End Sub
===========================================================================
This is the code I tried to use:
Sub SortDelete1()
Dim aRng As String
aRng = Sheets("FLRLSets").Range("AXO1").Value
With ActiveSheet
For Each cll In .Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value).Cells
.Range("AXO4").Value = cll.Value
SortDelete2
Next cll
End With
End Sub
Sub SortDelete2()
Dim aRng As String
Dim bRng As String
Application.ScreenUpdating = False
aRng = Sheets("FLRLSets").Range("AXO5").Value
bRng = Sheets("FLRLSets").Range("AXO7").Value
Sheets("FLRLSets").Select
Range(aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value).Select
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _
"aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ "this line gives an error
xlSortNormal
With ActiveWorkbook.Worksheets("FLRLSets").Sort
.SetRange Range("AXM2").Value & ":" & bRng & Range("AXM3").Value") 'this line of code gives an error
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply 'This line gives an error
End With
Range(aRng & Range("AXO8").Value & ":" & bRng & Range("AXO9").Value).Select
Selection.Delete Shift:=xlUp
Sheets("FLRLSets").Select
Range("AXQ1").Select
Application.ScreenUpdating = True
End Sub