Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA To Calculate Across Monthly Worksheet


Hi all,

My problem is that I need Week Totals to calculate the day dated sheets
before them and the Monthly total to calculate the Week Totals. Every month
the workbook will be different due to amount of days and dates in each
month. I was hoping if someone could help me out with code to make this work.

The ranges are B6:E24, G6:H24, K6:P24 (top team)
The ranges are B28:E49, G28:H49, K28:P49 (bottom team)


The ranges can also change if agents are added or leave

The code I use to build the Monthly sheet, copy the master and zoom

Sub NewSheets()
Dim Dte As Date, Dy As Date
Dim i As Long, j As Long, Dys As Long
Dim CountWeek As Boolean
Dim Shts As Long

Application. ScreenUpdating = False
'Get 1st of month
Dte = DateValue("1/" & Month(Date) & "/" & Year(Date))
'Count days in month
Dys = DateAdd("m", 1, Dte) - Dte
'Add requisite sheets
Shts = Sheets.Count
Sheets.Add after:=Sheets(Shts), Count:=(Dys + 1)
' Loop through sheets
For i = Shts + 1 To Sheets.Count - 1
'Get date
Dy = DateValue(i - Shts & "/" & Month(Date) & "/" & Year(Date))
Select Case Weekday(Dy)
'If weekday
Case 2, 3, 4, 5, 6, 7
If( ( dy - dte - dys ) = -1 )Then
j = j + 1
Sheets(i). Name = "WEEK " & j
Else
Sheets(i). Name = Format(Dy, "ddd dd-mm-yy")
CountWeek = True
End If
Case Else
'If Sunday
j = j + 1
If CountWeek = True Then
Sheets(i).Name = "WEEK " & j
End If
End Select
Next
'Add total
Sheets(Sheets.Count).Name = UCase(Format(Dy, "MMM")) & " MONTH END TOTAL"
Application.ScreenUpdating = False

Hope I have been clear.

Thank you for your time

Naz75
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default VBA To Calculate Across Monthly Worksheet

Naz75,

If the ranges change based on the agents, perhaps you can create a workbook
with the ranges for the days of the week and the ranges for the "week" sheets
in the workbook. Then you can run a routine to go through the workbook after
it has all the sheets named and drop the formulas/sum ranges into the proper
places.


"Naz75" wrote:


Hi all,

My problem is that I need Week Totals to calculate the day dated sheets
before them and the Monthly total to calculate the Week Totals. Every month
the workbook will be different due to amount of days and dates in each
month. I was hoping if someone could help me out with code to make this work.

The ranges are B6:E24, G6:H24, K6:P24 (top team)
The ranges are B28:E49, G28:H49, K28:P49 (bottom team)


The ranges can also change if agents are added or leave

The code I use to build the Monthly sheet, copy the master and zoom

Sub NewSheets()
Dim Dte As Date, Dy As Date
Dim i As Long, j As Long, Dys As Long
Dim CountWeek As Boolean
Dim Shts As Long

Application. ScreenUpdating = False
'Get 1st of month
Dte = DateValue("1/" & Month(Date) & "/" & Year(Date))
'Count days in month
Dys = DateAdd("m", 1, Dte) - Dte
'Add requisite sheets
Shts = Sheets.Count
Sheets.Add after:=Sheets(Shts), Count:=(Dys + 1)
' Loop through sheets
For i = Shts + 1 To Sheets.Count - 1
'Get date
Dy = DateValue(i - Shts & "/" & Month(Date) & "/" & Year(Date))
Select Case Weekday(Dy)
'If weekday
Case 2, 3, 4, 5, 6, 7
If( ( dy - dte - dys ) = -1 )Then
j = j + 1
Sheets(i). Name = "WEEK " & j
Else
Sheets(i). Name = Format(Dy, "ddd dd-mm-yy")
CountWeek = True
End If
Case Else
'If Sunday
j = j + 1
If CountWeek = True Then
Sheets(i).Name = "WEEK " & j
End If
End Select
Next
'Add total
Sheets(Sheets.Count).Name = UCase(Format(Dy, "MMM")) & " MONTH END TOTAL"
Application.ScreenUpdating = False

Hope I have been clear.

Thank you for your time

Naz75

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Monthly Inventory Usage Brian Excel Worksheet Functions 5 April 9th 09 04:08 PM
Calculate monthly contributions Chris T.[_2_] Excel Worksheet Functions 1 June 12th 07 08:49 AM
How could I calculate the monthly payment of GPM. PP Excel Discussion (Misc queries) 0 August 15th 06 03:39 AM
How to calculate IRR from a monthly income stream rflegeis Excel Discussion (Misc queries) 2 February 10th 06 09:07 PM
VBA Code to Calculate Monthly Interest NS Excel Programming 1 October 22nd 05 03:24 AM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"