title: How do I store a range of cells in a variable
body: <p>I'm currently working on a Sudoku program as a project in excel using VBA and I need to store a Range of cells in a variable.</p>
  
  <p>Something along the lines of this:</p>
  
  <pre><code>'''
  dim grid as string 
  
  grid = range("b3:j11")
  '''
  </code></pre>
  
  <p>But I'm not sure what to dim grid as.
  I've tried integer, string and range but grid never seems to have a value.
  I'm also assuming I'm not assigning the range to the variable correctly</p>
  
  <p>/////////////////////////////////</p>
  
  <p>Following the replies im pasting the code here.
  The duplicatecheck function looks through a range of cells to check if their are more than one of a certain number and then highlight the cells accordingly</p>
  
  <p>As i want to look through a different range of cells for different checks i need to make the range a variable so the function can be reused</p>
  
  <p>however when the variable grid is called in the duplicatecheck function it has no value and theirfor no cells are being checked</p>
  
  <pre><code>Dim row As Integer
  
  Dim col As Integer
  
  Dim grid As Variant
  
  Dim checkmark As Integer
  
  
  Sub Rowcheck()
  
      checkmark = 1
      row = 0
      col = 0
  
      grid = range("b3:j3").Value
  
      For row = 0 To 8
  
          duplicatecheck
  
      Next row
  </code></pre>
  
  <p>End Sub</p>
  
  <pre><code>Function duplicatecheck()
  
  Dim safe As Boolean
  
  Dim check As Integer
  
  Dim x As Integer
  
          ' check each number in a range for duplicates starting with 1
  For check = 1 To 9
      If Application.Worksheet.Function.CountIf(Selection.Offset(row, col), range(grid)).check = 1      Then 
  ' if number is only found once
  safe = True
      ElseIf Application.Worksheet.Function.CountIf(Selection.Offset(row, col), range(grid)).check &lt; 1 Then
  ' if the number is found less than once in the range
  safe = False
      ElseIf Application.Worksheet.Function.CountIf(Selection.Offset(row, col), range(grid)).check &gt; 1 Then
  ' if the number is found more than once
  Selection.Offset(row, x).range(grid).Interior.colour = vbBlue ' highlight the range red
  
          If checkmark = 1 Then
                For x = 0 To 8
                      Selection.Offset(row, x).range(geid).Value = check
                      Selection.Offset(row, x).range.ont.colour = vbRed
                 Next x
          ElseIf checkmark = 2 Then
                For x = 0 To 8
                      Selection.Offset(x, col).range(grid).Value = check
                      Selection.Offset(x, col).range.ont.colour = vbRed
  
                Next x
                safe = False
                   error = True
  
      If safe = False Then
         complete = False
      End If
  </code></pre>
  
  <p>End If
     End If
   Next check
  End Function</p>