title: Dynamically select Excel cells with VB .Net in a VS 2010 project
body: <p>I'm using Visual Studio 2010, to create a project from a Excel Workbook template. VS2010 already gives me a workbook with one worksheet. I added another one. The project consist of the following files:
  ThisWorkbook.vb
  Sheet1.vb
  Sheet2.vb</p>
  
  <p>Each file consist of class for each object: Sheet1.vb has its Sheet1 class, Sheet2.vb Sheet2 class and so on.</p>
  
  <p>From MSDN help and another sources, I understood I can access from on vb file, or another class, the other class objects using Globals statement:</p>
  
  <pre><code>    Me.Range("A10").Value = "Validation time:"
      Me.Range("B10").Value = ValidationTime_T1.Item(ValidationTime_T1.Count - 1) - ValidationTime_T0.Item(ValidationTime_T0.Count - 1)
  
  
      Dim x As Double
  
      Dim rowOffset As Integer
  
      rowOffset = 3
  
      For x = 0 To JobCounter
          Globals.Sheet2.Cells(x + rowOffset, 1) = x
          Globals.Sheet2.Cells(x + rowOffset, 2) = ASy_Start_Mem.Item(x)
          Globals.Sheet2.Cells(x + rowOffset, 3) = WSZ_Start_Mem.Item(x)
          Globals.Sheet2.Cells(x + rowOffset, 4) = WSZ_Start_Pk_Mem.Item(x)
          Globals.Sheet2.Cells(x + rowOffset, 5) = PFU_Start_Mem.Item(x)
  </code></pre>
  
  <p>As you can see, I move data from one sheet to another, or put data that is in memory to sheet2 from sheet1.</p>
  
  <p>So far, so good. There were not that many issues I could not solve by my self.</p>
  
  <p>I think is good to point out here that my background is C, C++, Perl and VBA in the last 4 years, so I'm struggling with VB since quite a bit already, I find .Net more useful, until I had to use it with Excel, it is giving me a hard time.</p>
  
  <p>Now, I need to select specific cells base on positions and it is not always the same position so I need to select them dynamically, NO HARD CODED, as I have found in MSDN, forums, StackOverFlow and different sites, the solution they give is to use:</p>
  
  <pre><code>Globals.Sheet2.Range("C7").Select()
  </code></pre>
  
  <p>And yeah, that's fine for specific cells for which you use a string to select.</p>
  
  <p>The problem is that I need to select different cells every time depending on the each day data, andt I don't know how to do it with Range. In the previous code you can see I used Cells for that.</p>
  
  <p>I've tried:</p>
  
  <pre><code>Globals.Sheet2.Range(Globals.Sheet2.Cells(2, 2), Globals.Sheet2.Cells(6, 3)).Select()
  </code></pre>
  
  <p>Because one of Range definitions states that I can receive as parameter two Cells objects, but gives an error. I've tried creating Range objects for the cell positions. I have used Object object with CType, and it also fails.</p>
  
  <p>If anyone could help how I can dynamically select cells, either with Range or Cells, or both, or if you have another solution, I will gladly appreciate it.</p>