title: EXCEL VBA - declaring range when the sheet name is a variable
body: <p>I use this line of code:</p>
  
  <pre><code>    ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort.SortFields.Add Key:=
      Range ("sName.Name[[#All],[Keyword]]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  </code></pre>
  
  <p>Now, this line is a part of a longer function that supposed to do the same thing for a wider list of sheets. Therefore, I need to change the range selection:</p>
  
  <pre><code>  Range ("sName.Name[[#All],[Keyword]]")
  </code></pre>
  
  <p>To be based on a variable, I just can't find the right solution on how to do it.
  ** I tried a few options, improvised, didn't work.</p>
  
  <p>Thanks in advance.</p>
  
  <p>That is the full code btw:</p>
  
  <pre><code>Sub Filter()
  'Application.ScreenUpdating = False
      Call Filtering("US")                  'To prepare Data for All Keywords
      MsgBox "Updated"
  'Application.ScreenUpdating = True
  End Sub
  
  Function Filtering(sName As String)
  '
  ' Filtering Macro
  '
  
  '
      Sheets(sName).Select
      ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort.SortFields.Clear
      ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort.SortFields.Add Key:=
          Range ("sName.Name[[#All],[Keyword]]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  
      With ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
      ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort.SortFields.Clear
      ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort.SortFields.Add Key:= _
          Range("sName.Name[[#All],[Position]]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal _
  
      With ActiveWorkbook.Worksheets(sName).ListObjects(sName).Sort
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
      ActiveSheet.ListObjects(sName).Range.AutoFilter Field:=2, Criteria1:="&lt;=20" _
          , Operator:=xlAnd
  End Function
  </code></pre>