Help with VBA code

OliviaT

New Member
Joined
May 28, 2015
Messages
17
Hi,

I need help with the vba code below. The code works but only on the current worksheet that I select. It won't loop through all the remaining worksheets in my workbook? I do NOT have a problem with the formulas. I want the formulas (Date and Sumif) to be copied to the other worksheets (currently 50) excluding the 9 mentioned below. I have tried to search the forum but can't seem to find a solution. The exact number of worksheets in my workbooks will vary each month.

I am new to vba. The code below was piecemeal-ed from some other code that I have founded to work but I inserted my new formulas in there instead of the original formula.

Could someone please let me know how to get my formulas copied to the other worksheets? Thank you in advance for your time and assistance.




Sub Macro2()
je = "JE"
qsumttm = "QSumTTM"
dttm = "DetailTTM"
qsum = "QSum"
d = "Detail"
wttm = "WalTTM"
w = "Wal"
staff = "Stafflisting"
Sum = "Summary"

Application.Calculation = xlCalculationManual
Dim Sht As Worksheet

For Each Sht In ActiveWorkbook.Sheets
With Sht
If Sht.Name <> je And Sht.Name <> qsumttm And Sht.Name <> dttm And Sht.Name <> qsum And Sht.Name <> d And Sht.Name <> wttm And Sht.Name <> w And Sht.Name <> staff And Sht.Name <> Sum Then

Range("S10").Select
ActiveCell.FormulaR1C1 = "=DATE(YEAR(RC[-3]),1,1)"
Range("S11").Select
ActiveCell.FormulaR1C1 = "=SUMIF(R10C5:R10C16,"">=""&R10C19,RC[-14]:RC[-3])"
Selection.AutoFill Destination:=Range("S11:S135"), Type:=xlFillDefault


End If

End With
Next Sht
Application.Calculation = xlCalculationAutomatic
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

Forum statistics

Threads
1,215,338
Messages
6,124,357
Members
449,155
Latest member
ravioli44

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