Determining if a worksheet has formulas in it in VBA

nyconfidential

New Member
Joined
Jul 22, 2015
Messages
49
Office Version
  1. 365
  2. 2016
Hi all - working on a function that copies formulas from one worksheet to another. I'm looping through every sheet in the workbook - when I get to a sheet that has no formulas, I get that "1004 - No cells Found" error. Now I guess I can handle this through error handling, but is there a simple way to determine if a sheet has formulas before I start the meat of my sub? I'm trying an If statement at the moment(If ThisWorkbook.Sheets(rCell.Value).Cells.SpecialCells(xlCellTypeFormulas).count > 0 Then), but that isn't working(I get the same 1004 error when I step through that line). Anyone have any thoughts? Thanks in advance.


Code:
For Each rCell In rRng.Cells 
If SheetExists(rCell.Value) = True Then
        Application.DisplayAlerts = False
        Application.ScreenUpdating = False
        If ThisWorkbook.Sheets(rCell.Value).Cells.SpecialCells(xlCellTypeFormulas).count > 0 Then
            For Each r In ThisWorkbook.Sheets(rCell.Value).Cells.SpecialCells(xlCellTypeFormulas)
                ActiveWorkbook.Sheets(rCell.Value).Range(r.Address).Formula _
                = ThisWorkbook.Sheets(rCell.Value).Range(r.Address).Formula
            Next r
    End If
Next rCell
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How about
Code:
   Dim Flg As Boolean
   
   For Each rCell In rRng.Cells
      If SheetExists(rCell.Value) = True Then
         Application.DisplayAlerts = False
         Application.ScreenUpdating = False
         On Error Resume Next
         Flg = ThisWorkbook.Sheets(rCell.Value).Cells.SpecialCells(xlCellTypeFormulas)
         On Error GoTo 0
         If Flg Then
            For Each r In ThisWorkbook.Sheets(rCell.Value).Cells.SpecialCells(xlCellTypeFormulas)
               ActiveWorkbook.Sheets(rCell.Value).Range(r.Address).Formula _
               = ThisWorkbook.Sheets(rCell.Value).Range(r.Address).Formula
            Next r
         End If
      End If
      Flg = False
   Next rCell
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top