title: Excel-VBA: Copy-Paste formatting of visible cells to visible cells
body: <p>I am looking to write a macro to copy the format of only the visible (i.e. non-hidden, non-filtered out) cells of a selection in one sheet into only the visible cells in a selection in another sheet.</p>
  
  <p>My VBA is a bit rusty, so if anyone can either help me with the code I wrote myself, or provide an alternative bit of code, I would be very thankful.</p>
  
  <p>Here is my current code (with commented-out code incase someone suggests i uncomment that code):</p>
  
  <pre><code>Sub Copy_Paste_Visible()
  
  
  
      Set CopyRng = Application.Selection
      CopyRng = CopyRng.SpecialCells(xlCellTypeVisible).Copy' _
          'Destination:=Range("A1").Offset(ColumnOffset:=1)
  
  
  
      Set PasteRng = Application.InputBox("Paste to :", xTitleId, Type:=8)
  
      PasteRng = PasteRng.SpecialCells(xlCellTypeVisible) '.Copy _
           'Destination:=Range("A11").Offset(ColumnOffset:=1)
  
      'CopyRng.Copy
      PasteRng.Parent.Activate
      'PasteRng.Activate
      PasteRng.PasteSpecial xlPasteFormats
      Application.CutCopyMode = False
  
  End Sub
  </code></pre>
  
  <p>With this code, on line </p>
  
  <pre><code>PasteRng.Parent.Activate
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <p><a href="https://i.stack.imgur.com/LxGlu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LxGlu.jpg" alt="enter image description here"></a></p>
  
  <p>If anyone is able to provide any input, that would be great.</p>