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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,877
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Deepas

New Member
Joined
Mar 2, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
thankyou, also can you help me with the formula to delete the last row of all sheet barring the 4 sheets
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,877
Office Version
  1. 365
Platform
  1. Windows
As that's a totally different question, it needs a new thread. Thanks
 

Forum statistics

Threads
1,148,018
Messages
5,744,355
Members
423,863
Latest member
teehexcel

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
Top