1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

  2. Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User


  3. When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel VBA: Creation of Array

Discussion in 'VBA Macros' started by game_federer, Jul 13, 2017.

  1. game_federer

    game_federer New Member

    Hi All,
    I have a number stored in FromMonth Variable(Say)
    Eg. FromMonth = 5.

    Now I need all the natural numbers less than and equal to 5 in an array and then pass into into the autofilter field.

    Your help would be greatly appreciated.

  2. NARAYANK991

    NARAYANK991 Excel Ninja

    Hi ,

    Try this :
    Code (vb):

    Public Sub auto_filter()
              Dim FromMonth As Integer
              Dim Crit1 As String
              FromMonth = 7
              For i = 1 To FromMonth
                  Crit1 = Crit1 & "," & Str(i)
              Crit1 = Mid(Crit1, 2)
              ActiveSheet.Range("D1:L11").AutoFilter Field:=4, Criteria1:=Split(Crit1, ","), Operator:=xlFilterValues
    End Sub
    Change the highlighted portions to suit.

    Chirag R Raval likes this.
  3. game_federer

    game_federer New Member

    Hi Narayan,

    It worked perfectly.
    Thank you for your time and knowledge.
  4. Marc L

    Marc L Excel Ninja


    just using standard Excel :​
    Code (vb):
        FromMonth% = 5
        V = Evaluate("TRANSPOSE(ROW(1:" & FromMonth & "))")
    game_federer and Chirag R Raval like this.

Share This Page