I'm trying to put some macro buttons on a template that teachers use to analyze testing data. The template has a column for each question. The questions always begin on column C, but may range to any column depending on the number of questions on the test. The buttons would sort the questions by different rows (question #, % correct, type of question, etc.)
The following recorded macro does what I want, except, the range will not always be what it recorded here. It may be from C:BD or from C:Z or whatever else. How can I adapt the code to adjust for whatever number of columns there might be?
I would also like to have a similar command for another section of columns in the template (from BL:DE in the attached sample), but in that case both the beginning and ending columns would be variable. That section would always begin two columns to the right of the "Total Tested" columns.
A sample file is attached and linked to below.
Sub Macro11()
Columns("C:C").Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Worksheets("TestResults").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TestResults").Sort.SortFields.Add Key:=Range( _
"C8:BD8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TestResults").Sort
.SetRange Range("C1:BD382")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
Attachment 341532
https://drive.google.com/file/d/0B0N...it?usp=sharing
Bookmarks