title: Copying only the visible cells from visible worksheets into a new workbook, excel 2007 VBA
body: <ul>
  <li>I have a master spreadsheet <code>Master Spreadsheet.xlsm</code> and I want to use it to create  another spreadsheet defined by <code>OutputFN</code>. </li>
  <li>This second spreadsheet needs to be a copy of the first but only containing the visible cells from visible worksheets in the first.</li>
  </ul>
  
  <p>I have found code to copy just the visible sheets and other code to copy just the visible cells but not the two together. Any help would be much appreciated.</p>
  
  <p>This is what I've got so far: </p>
  
  <pre><code>Private Sub saveone()
  
  Dim OutputFN As String
  Dim OutputWB As Workbook
  Dim SourceWB As Workbook
  Dim i As Integer
  
  i = 1
  Set SourceWB = Application.ActiveWorkbook
  OutputFN = ThisWorkbook.Worksheets("Setup Page").Range("B12").Value
  Set OutputWB = Workbooks.Add
  
  
  'Selects active (not hidden cells) from visible sheets and copies
  
  For Each Sheet In ThisWorkbook.Sheets
  If Sheet.Visible = True Then
  ThisWorkbook.ActiveSheet.Cells. _
  SpecialCells(xlCellTypeVisible).Copy
  
  'Pastes into new workbook
  Worksheets(i).Range("A1").Select
  Selection.PasteSpecial Paste:=xlPasteValues
  Selection.PasteSpecial Paste:=xlPasteFormats
  
  'Saves new file as output filename in the directory created earlier
   ActiveWorkbook.SaveAs (OutputFN)
  
  i = i + 1
  End If
  Next
  
  End Sub
  </code></pre>