Hello,
I have an excel workbook with 24 sheets. I have created a macro (see below) which I hoped to use on all 24.
Unfortunately it only seems to work 'properly' on the first sheet (the sheet the macro was created on) and not 'properly' on the rest.
When I say properly I mean the macro is a 'shortcut' to Sort and Filter - Sort smallest to largest using Rand=()
So on the first sheet the Rand=() numbers change and the content in the colums to the right of the Rand=() change (random order), however on other sheets only the Rand=() number changes, but the content in the colums to the right of the Rand=() do not change.
Any suggestions welcome!!
I have an excel workbook with 24 sheets. I have created a macro (see below) which I hoped to use on all 24.
Unfortunately it only seems to work 'properly' on the first sheet (the sheet the macro was created on) and not 'properly' on the rest.
When I say properly I mean the macro is a 'shortcut' to Sort and Filter - Sort smallest to largest using Rand=()
So on the first sheet the Rand=() numbers change and the content in the colums to the right of the Rand=() change (random order), however on other sheets only the Rand=() number changes, but the content in the colums to the right of the Rand=() do not change.
Any suggestions welcome!!
VBA Code:
Sub Macro1()
'
' Macro1 Macro
' random
'
' Keyboard Shortcut: Ctrl+q
'
Range("C3").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("C3:N13")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("C3:N13")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D16").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D16"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("D16:N2063")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D16"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("D16:N2063")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub