Firstly I'm having issues setting up the percentile application not sure what to put as array and as myVar. I've had a look at a few codes and not sure what and why they put certain values there.
Secondly I want two different percentile calculations to run on rows 16-79 which each are unique to each other. The columns can't be set as the range changes from sheet to sheet. I have code below which finds the last column with data and creates 2 columns: "20th Percentile" and "80th Percentile" after it. So I'm thinking this can be used to help in setting up the range. This needs to be ran on multiple sheets.
Sub create_columns_test2()
Dim WS As Worksheet
Dim x As Integer
Dim array(???) As Variant?
'What do I set my array as? why variant?
Dim myVar as Double?
'What does double mean
For Each WS In ActiveWorkbook.Worksheets
With WS
If .Cells.Find("20th Percentile") Is Nothing And _
.Cells.Find("80th Percentile") Is Nothing Then
x = .UsedRange.Columns.Count
.Cells(16, x + 2).Value = "20th Percentile"
myVar = Application.WorksheetFunction.Percentile(Array(16, x - 1), 0.2)
.Cells(16, x + 3).Value = "80th Percentile"
myVar = Application.WorksheetFunction.Percentile(Array(16, x - 2), 0.8)
'I want the percentile to run from rows 16 to 79 individually
'from column C to the column before the matching column I've just created
End If
End With
Next WS
For Each WS In ActiveWorkbook.Worksheets
WS.Range("N:Q").EntireColumn.AutoFit
Next WS
End Sub