title: Get maximum value of columns in Excel with macro
body: <p>First of all I have no idea of writing macros in excel, but now I have to write a code for a friend. So here we go. 
  In my excel sheet I have a table which holds some producers as columns and 12 months of the year as rows. In their intersecting cell it's written the amount of products produced by the producer during that month. Now I need to find maximum and minimum values of produced goods within each month and output the producers of that goods.
  I found a code for a similar problem, but I don't understand it clearly and it has errors.
  Here is the code:</p>
  
  <pre><code>Sub my()
  Dim Rng As Range, Dn As Range, Mx As Double, Col As String
  Set Rng = Range(Range("A1"), Range("A6").End(xlUp))
  ReDim ray(1 To Rng.Count)
  
  For Each Dn In Rng
  Mx = Application.Max(Dn)
      Select Case Mx
          Case Is = Dn.Offset(, 0): Col = "A"
          Case Is = Dn.Offset(, 1): Col = "B"
          Case Is = Dn.Offset(, 2): Col = "C"
          Case Is = Dn.Offset(, 3): Col = "D"
      End Select
          ray(Dn.Row - 1) = Col
  Next Dn
  
  Sheets("Sheet2").Range("A2").Resize(Rng.Count) = Application.Transpose(ray)
  End Sub
  </code></pre>
  
  <p>I get the following error:
  <code>Run-time error'9': Subscript out of range.</code>
  So my question is, what does this error mean and what do I need to change in this code to work?</p>
  
  <p><strong>EDIT1</strong>:
  OK, now the error is gone. But where do I get the results? </p>
  
  <p><strong>EDIT2</strong>
  I know this line is responsible for inserting the results in specified place, but I cant see them after execution. What's wrong with that?</p>