Please refer to the code below. I´m trying to sort the content of my sheet based on the cell input on the Range("AD2"). The problem sits on the line key1:=rng_sort which I believe is being called in a wrong way.
What I want to do is change the column that is sorted based on the condition that is chosen on the cell
Range("AD2"). On that cell i´ve a data validation list as seen below:

If Range("AD2") = "Event"i want to sort the column I. If it equals "Vo" i want to sort the column J.
Any Idea what i might be doing wrong?
Thank you.
Sub sortEvent()
Sheets(1).Activate ' activate sheet(1)
Dim n As Integer
Dim j As Integer
Dim i As Integer
Dim h As Integer
Dim Lastrow As Integer
Dim ng_sort As Range
Lastrow = Cells(Rows.Count, "I").End(xlUp).Row ' guarda o indice da ultima linha com conteudo da coluna I. Mesmo havendo vazios identifca a ultima linha
Length = Range(Range("I10"), Range("I" & Lastrow)).Rows.Count ' dimensão da coluna O ate a ultima celula com conteudo começando na O6
For firstrow = 1 To Length ' loop na coluna O
If Range("C2").Offset(firstrow, 0).Interior.Color = RGB(68, 114, 196) Then
Exit For
End If
Next firstrow
If Range("AD2") = "Event" Then
rng_sort = Range("I1")
Else
rng_sort = Range("J1")
End If
n = 0
j = 1
For i = 1 To Length ' loop na coluna I
If Range("C2").Offset(firstrow + i, 0).Value <> "" Then
n = n + 1
Else
Range(Range("C2").Offset(firstrow + j, 0), Range("C2").Offset(firstrow + j + n - 1, 0)).EntireRow.sort key1:=rng_sort, order1:=xlAscending, Header:=xlNo
j = j + n + 1
n = 0
End If
Next i
End Sub
AD2. And also an explanation of what you mean by working great except ... would be useful in helping us help you. Take a look at the Help pages for How to create a Minimal, Complete, and Verifiable example