title: Changing target cell on VBA Excel
body: <p>I'm just trying to figure out if there is a way to change the target cell to run the same code. This code basically opens a directory folder based on the cell <em>A1</em> but what I want to happen is add a macro button on the same row that uses the value of the cell on that row. (For example, this my code uses the data on <em>A1</em>, I want the code to do that same for <em>A2</em> if I put the macro button on row 2)</p>
  
  <pre><code>Sub OpenFolder()
  
      Dim MyFolder As String
      Dim JobNumber As String
      Dim JobYearLeft As String
      Dim JobYear As String
      Dim FolderNumber As String
      Dim i As Integer
      Dim FirstFolder As String
  
      JobNumber = Right(Range("A1"), Len(Range("A1")) - 3)
      JobYearLeft = Right(Range("A1"), Len(Range("A1")) - 1)
      JobYear = Left(JobYearLeft, Len(JobYearLeft) - 4)
  
      i = CInt(JobNumber)
  
      Select Case i
          Case 0 To 500
          FolderNumber = "0001_0500"
              Case 500 To 1000
              FolderNumber = "0501_1000"
                  Case 1000 To 1500
                  FolderNumber = "1001_1500"
                      Case 1500 To 2000
                      FolderNumber = "1501_2000"
      End Select
  
  
      If (JobYear = 17) Then
          FirstFolder = "M:\2017\" &amp; FolderNumber &amp; "\" '&amp; Range("A1").Value &amp; "*" &amp; "\"
      Else
          MyFolder = "M:\2016\" &amp; FolderNumber &amp; "\" '&amp; Range("A1").Value &amp; "*" &amp; "\"
      End If
  
      If (JobYear = 17) Then
          MyFolder = "M:\2017\" &amp; FolderNumber &amp; "\" &amp; Range("A1").Value &amp; "*" '&amp; "\"
      Else
          MyFolder = "M:\2016\" &amp; FolderNumber &amp; "\" &amp; Range("A1").Value &amp; "*" '&amp; "\"
      End If
  
      MyFolder = Replace(MyFolder, " ", "")
  
      Dim OpenThisFolder As String
      Dim GoToFolder As String
  
      MyFolder = Dir(MyFolder, vbDirectory)
  
      GoToFolder = FirstFolder &amp; MyFolder &amp; "\"
      GoToFolder = Replace(GoToFolder, " ", "")
      ActiveWorkbook.FollowHyperlink GoToFolder
  
  End Sub
  </code></pre>