VBA code to select from an HTML drop down, using value rather than index
<p>I'm fairly new to VBA and HTML. I am writing a VBA macro which navigates through a website, before filling in a web form. </p>

<p>During navigation, the script needs to pick an option from a drop-down menu. I am currently using the following (no doubt awful, but functional) code, which finds the correct drop-down menu before selecting the option at index 2. </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Set dropOptions = HTMLDoc.getElementsByTagName("select")
For Each op In dropOptions
If op.getAttribute("name") = "tilastojakso" Then
op.Focus
op.selectedIndex = 2
Exit For
End If
Next op</code></pre>
</div>
</div>
</p>

<p>And here is the HTML of the relevant dropdown:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;tr&gt;
    &lt;td&gt;Statistical period&lt;/td&gt;
    &lt;td colspan="2"&gt;&lt;select name="tilastojakso" &gt;
&lt;option value="2016-07"&gt;2016-07 (deadline 12.08.2016)&lt;/option&gt;
&lt;option value="2016-06"&gt;2016-06 (deadline 14.07.2016)&lt;/option&gt;
&lt;option value="2016-05"&gt;2016-05 (deadline 14.06.2016)&lt;/option&gt;
&lt;option value="2016-04"&gt;2016-04 (deadline 16.05.2016)&lt;/option&gt;
&lt;option value="2016-03"&gt;2016-03 (deadline 14.04.2016)&lt;/option&gt;
&lt;option value="2016-02"&gt;2016-02 (deadline 14.03.2016)&lt;/option&gt;
&lt;option value="2016-01"&gt;2016-01 (deadline 12.02.2016)&lt;/option&gt;
&lt;option value="2015-12"&gt;2015-12 (deadline 18.01.2016)&lt;/option&gt;
&lt;option value="2015-11"&gt;2015-11 (deadline 14.12.2015)&lt;/option&gt;
&lt;option value="2015-10"&gt;2015-10 (deadline 13.11.2015)&lt;/option&gt;
&lt;option value="2015-09"&gt;2015-09 (deadline 14.10.2015)&lt;/option&gt;
&lt;option value="2015-08"&gt;2015-08 (deadline 14.09.2015)&lt;/option&gt;
&lt;option value="2015-07"&gt;2015-07 (deadline 14.08.2015)&lt;/option&gt;
&lt;option value="2015-06"&gt;2015-06 (deadline 14.07.2015)&lt;/option&gt;
&lt;option value="2015-05"&gt;2015-05 (deadline 12.06.2015)&lt;/option&gt;
&lt;option value="2015-04"&gt;2015-04 (deadline 18.05.2015)&lt;/option&gt;
&lt;option value="2015-03"&gt;2015-03 (deadline 16.04.2015)&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;</code></pre>
</div>
</div>
</p>

<p>The problem: </p>

<p>I want to select from the dropdown based on option value, rather than index. Let's say I have a variable called "period" which contains the string "2016-04". I want the script to pick the option with a value that matches the string stored in "period". I haven't been able to find an answer that I can understand. </p>