title: Linking UserForm answers to change filepath in a Macro
body: <p>I have a summary workbook which pulls data from multiple excel workbooks saved in a folder. Each folder contains workbooks for data for a specific year and month. For example, C:\Desktop\Summaries\MONTH YEAR</p>
  <p>I also have a UserForm that lets you choose the year and month. I would like for the answers from my UserForm to inform the file path.
  <a href="https://i.stack.imgur.com/IMUWv.png" rel="nofollow noreferrer">See picture</a></p>
  <p>I would like to change the Month and Year of this file path depending on what is chosen in my UserForm</p>
  <p>For example, if I want to pull data for February 2021, I will choose February and 2021 from my UserForm. When I press submit, I then would like my file path to change to C:\Desktop\Summaries\February 2021</p>
  <p>Then my code will run to summarise the data in that folder. <strong>How do I link my UserForm answers to a change in my file path?</strong></p>
  <p>See below the code I use to summarise:</p>
  <pre><code>Dim desWS As Worksheet, srcWB As Workbook
  Set desWS = ThisWorkbook.Sheets(&quot;Data&quot;)
  Dim LastRow As Long
  Const strPath As String = &quot;C:\Desktop\Summaries\MONTH YEAR&quot;
  ChDir strPath
  strExtension = Dir(strPath &amp; &quot;*.xlsx&quot;)
  Do While strExtension &lt;&gt; &quot;&quot;
      Set srcWB = Workbooks.Open(strPath &amp; strExtension)
      With srcWB.Sheets(&quot;Macro&quot;)
             desWS.Cells(desWS.Rows.Count, &quot;B&quot;).End(xlUp).Offset(1, 0).Resize(, 22).Value = Application.WorksheetFunction.Transpose(.Range(&quot;C3:C24&quot;).Value)
      End With
      srcWB.Close False
      strExtension = Dir
  Loop
  Application.ScreenUpdating = True
  </code></pre>