We have a small Book Club. We read the book and then score it.
To keep track of the books I use a macro that takes the scores adds the latest book and then sorts the list from highest to lowest points.
I have to manually update the fields with each new book.
I tried to automate the process recently by using:
Meaning of .Cells(.Rows.Count,“A”).End(xlUp).row
which counts the number of empty cells upwards until it reaches a cell with some data in it and then performs the operation on it.
The modified macro works until it tries to sort the list and it then stops working.
How I can modify the sort?
This is the Book Club file: Page 1.
This is the Book Club file: Page 2.
This is the modified macro which works until the sort then stops.
Sub PositionIndex()
'
' PositionIndex Macro
' This macro sorts the ongoing position of the most popular books.
'
' Keyboard Shortcut: Ctrl+Shift+X
Dim wb As Workbook
Dim ws As Worksheet
Dim symbol As String
Dim n As Integer
Dim lastrow As Long
Sheets("Position Series").Select
Find the last used row in a Column: column K in this example
With ActiveSheet
lastrow = .Cells(.Rows.Count, "K").End(xlUp).Row
End With
MsgBox lastrow
Dim DataRange As Range
Set DataRange = Range("C7:K" & lastrow)
DataRange.Select
Selection.ClearContents
Sheets("Time Series").Select
'Find the last used row in a Column: column "Q" in this example
With ActiveSheet
lastrow = .Cells(.Rows.Count, "Q").End(xlUp).Row
End With
MsgBox lastrow
Range("Q9:Q" & lastrow).Select
Selection.Copy
Sheets("Position Series").Select
Range("K7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Time Series").Select
'Find the last used row in a Column: column "I" in this example
With ActiveSheet
lastrow = .Cells(.Rows.Count, "I").End(xlUp).Row
End With
MsgBox lastrow
Range("C9:I" & lastrow).Select
Selection.Copy
Sheets("Position Series").Select
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Position Series").Select
With ActiveSheet
lastrow = .Cells(.Rows.Count, "K").End(xlUp).Row
End With
MsgBox lastrow
Range("C7:K" & lastrow).Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Position Series").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Position Series").Sort.SortFields.Add Key:=Range( _
"K7:K" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Position Series").Sort
.SetRange = Range("C7:K" & lastrow).Select
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
Sheets("Time Series").Select
Range("A2").Select
End Sub