title: Hiding Cells in Excel with a macro
body: <p>I am desperatly looking for help with my excel macro to hide rows if a certain criteria is met. I have tried to enter all the code previously provided in other question answers and just cannot get the damn thing to run. </p>
  
  <p>My code below runs wonderfully without the row hidden part</p>
  
  <p>I need the following to calc before the template is generated</p>
  
  <pre><code>If range F30 to J30 is blank then rows 29 to 30 must be hidden
  If range F33 to J33 is blank then rows 32 to 33 must be hidden
  If range F30 to J33 is blank then rows 28 to 35 must be hidden
  </code></pre>
  
  <p>Can you please assist me</p>
  
  <pre class="lang-cs prettyprint-override"><code>Function RangeName(sName As String) As String
  RangeName = Application.Substitute(sName, " ", "_")
  End Function
  Sub MergePrint()
  Dim wsForm As Worksheet, wsData As Worksheet
  Dim sRngName As String, r As Long, c As Integer
  Set wsForm = Worksheets("Template")
  Set wsData = Worksheets("DataSource")
  With wsData.Cells(1, 1).CurrentRegion
  For r = 2 To .Rows.Count
  If Not wsData.Cells(r, 1).EntireRow.Hidden Then
  For c = 1 To .Columns.Count
  sRngName = wsData.Cells(1, c).Value
  Range(RangeName(sRngName)).Value = wsData.Cells(r, c)
  Next
  wsForm.PrintOut
  End If
  Next
  End With
  End Sub
  </code></pre>