Find and select

trevormay99

New Member
Joined
Aug 25, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I recorded a macro that searches for excel formulas, selects, copies and pastes the formulas to the top of the spreadsheet, more specifcally N2, the code runs and functions properly when used alone, however when I call the macro into another macro and run them together I get an run time error 1004 no cells found. Is there anyway I can get this macro added into another macro so they can run together and still function properly

VBA Code:
Private Sub SumFix()
'
' SumFix Macro
'

'
    Selection.SpecialCells(xlCellTypeFormulas, 23).Select
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-18
    Range("N2").Select
    ActiveSheet.Paste
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
First you can simplify this code quite a bit.
VBA Code:
Private Sub SumFix()
    On Error GoTo NoCells
    Selection.SpecialCells(xlCellTypeFormulas, 23).Copy Range("N2")
    Exit Sub
NoCells:
    MsgBox "No formulas found in " & Selection.Address
End Sub

If there are no formulas in Selection when SumFix is called then you will get this error, which may be your problem. I have added error handling.

I don't know if that will fix your problem but there is no hope of fixing it until we see all the code. Please show us the other code that you call this from, and identify which line of code causes the error.
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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