macro to run the formula on select worksheets

Deepas

New Member
Joined
Mar 2, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
hi have this macro which works fine, but i want to run it on all sheets in the workbook, barring 4.

i'm new to macros, can someone hep detect the error in this.

VBA Code:
Sub Macro1()
   
' Keyboard Shortcut: Ctrl+Shift+P
   
    Dim Ws As Worksheet
   
    For Each Ws In Worksheets
      Select Case Ws.Name
         Case "Sheet1", "live Sheet", "Total P&L", "Sheet1 (formula)"
         Case Else

Selection.End(xlUp).Select
    Range("V15").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-11]=""open"",0,R[-1]C[-1]*(RC[-20]-R[-1]C[-20]))"
    Range("V15").Select
    Selection.AutoFill Destination:=Range("V15:V1361")
    Range("V15:V1361").Select
    Range("Y15").Select
    Selection.End(xlUp).Select
    Range("Y15").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-14]=""open"",0,R[-1]C[-1]*(RC[-22]-R[-1]C[-22]))"
    Range("Y15").Select
    Selection.AutoFill Destination:=Range("Y15:Y1361")
    Range("Y15:Y1361").Select
        End Select
   Next Ws
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
VBA Code:
Sub Macro1()
   
   ' Keyboard Shortcut: Ctrl+Shift+P
   
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      Select Case Ws.Name
         Case "Sheet1", "live Sheet", "Total P&L", "Sheet1 (formula)"
         Case Else
            With Ws
               .Range("V15:V1361").FormulaR1C1 = _
                  "=IF(RC[-11]=""open"",0,R[-1]C[-1]*(RC[-20]-R[-1]C[-20]))"
               .Range("Y15:Y1361").FormulaR1C1 = _
                  "=IF(RC[-14]=""open"",0,R[-1]C[-1]*(RC[-22]-R[-1]C[-22]))"
            End With
      End Select
   Next Ws
End Sub
 
Upvote 0
Solution
thankyou, also can you help me with the formula to delete the last row of all sheet barring the 4 sheets
 
Upvote 0
As that's a totally different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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