title: How to delete a specific range when specific cell is empty?
body: <p>I have the following problem.<br>
  In an excel spreadsheet I am populating a calendar schedule.
  Based on a drop down list, you can change the months and year, and therefore the dates adjust automatically to the week days.  </p>
  
  <pre><code>Fixed week days = `E6:R6`   
  Calendar dates  = `E7:R7`    
  Work Shifts     = `E8:R15`  
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/sWZbO.jpg" alt="enter image description here"></p>
  
  <p>Now, when the new schedule populates and like in this case, there is no "Sunday" before October 1st, then I need to have all names from range <code>E8:E15</code> removed.  </p>
  
  <p><img src="https://i.stack.imgur.com/YZuog.jpg" alt="enter image description here"></p>
  
  <p>I've tried an IF THEN ELSEIF in the sub, and that works, but only for the first range - <code>E8:E15</code>.  If I switch the month to September, and we start with a Saturday, then all cells maintain their values, but <code>E8:E15</code>.  It's like I can only do "1" IF loop and then it stops.</p>
  
  <p><img src="https://i.stack.imgur.com/41VT8.jpg" alt="enter image description here"></p>
  
  <p>I'm looking for code that loops through all weeks to check if the cell shows a date or is empty.  The only possible weeks with no dates would be week 1, and week 5 + 6. As you can see in the last pic, depending on how long the month is, more or less dates show.  </p>
  
  <p><img src="https://i.stack.imgur.com/wk2Dj.jpg" alt="enter image description here"></p>
  
  <hr>
  
  <p>UPDATE:
  Hi there, it works now and I was able to work it out the following way.</p>
  
  <p><strong>My original code was:</strong></p>
  
  <pre><code>If Sheets("schedule").Range("E5") = "" Then
  Sheets("Schedule").Range("E8:E15").ClearContents
    Elseif Sheets("schedule").Range("G5") = "" Then
    Sheets("Schedule").Range("G8:G15").ClearContents
  </code></pre>
  
  <p>..and so on for all other ranges of my calendar.
  End if </p>
  
  <p><strong>The new code is:</strong>
  What I simply tried next was leaving them all separate.</p>
  
  <pre><code>If Sheets("schedule").Range("E5") = "" Then
  Sheets("Schedule").Range("E8:E15").ClearContents
  End if
  
  If Sheets("schedule").Range("G5") = "" Then
  Sheets("Schedule").Range("G8:G15").ClearContents
  End if
  </code></pre>
  
  <p>.... and so on.</p>
  
  <p>And now it's running just fine.
  For some reason it was not able to run through several IF-loops before the end if.
  Thanks everyone for all the fast help!
  I'll definitely be back when I have another question about Excel and VBA :)</p>