Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Help with VB code - average of numbers over specified weeks

I have a spreadsheet that has weeks 1-9 (columns C-K). In each week is 3
numbers (rows 4-6). Those numbers get added together to get a total for that
week (row 7).
I need help with creating the VB script that when run adds the totals
together and gives an average for a specified week range.

Example: user clicks a button and a dialog box comes up where they enter in
the week range in textboxes. So textbox1.text could be 3 and textbox2.text
could be 7. Then the user clicks an ok button and the script runs. The script
would add together the totals for week 3,4,5,6,7 (in row 7) then divide that
sum by: number of weeks x 3 (in this case 15)
Another example: user enters in week 6 to week 9, they click ok and the
script runs. It would add the totals for week 6,7,8,9 then divide that sum
by: number of weeks x 3 (in this case 12)

The week range will be different all the time, depending on what specified
week average I need at that time. Can anyone help me with this?

Thanks for any help you can provide,
Phil

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with VB code - average of numbers over specified weeks

Sub myAVerage()
Dim rng As Range
Dim iStart, iEnd

Set rng = Range("C7")
iStart = 3
iEnd = 7

Do
iStart = InputBox("Input first column (1-7)")
Loop Until iStart = "" Or (iStart 0 And iStart < 8)

If iStart < "" Then
Do
iEnd = InputBox("Input first column (1-7)")
Loop Until iEnd = "" Or (iEnd 0 And iEnd < 8)

myval = Application.Sum(rng(1, CLng(iStart)).Resize(, iEnd - iStart
+ 1)) / ((iEnd - iStart + 1) * 3)

MsgBox myval
End If

End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"phil-rge-ee" wrote in message
...
I have a spreadsheet that has weeks 1-9 (columns C-K). In each week is 3
numbers (rows 4-6). Those numbers get added together to get a total for

that
week (row 7).
I need help with creating the VB script that when run adds the totals
together and gives an average for a specified week range.

Example: user clicks a button and a dialog box comes up where they enter

in
the week range in textboxes. So textbox1.text could be 3 and textbox2.text
could be 7. Then the user clicks an ok button and the script runs. The

script
would add together the totals for week 3,4,5,6,7 (in row 7) then divide

that
sum by: number of weeks x 3 (in this case 15)
Another example: user enters in week 6 to week 9, they click ok and the
script runs. It would add the totals for week 6,7,8,9 then divide that sum
by: number of weeks x 3 (in this case 12)

The week range will be different all the time, depending on what specified
week average I need at that time. Can anyone help me with this?

Thanks for any help you can provide,
Phil



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Help with VB code - average of numbers over specified weeks

Thanks, Bob. Man you guys are good. I've taught myself some VB, but when it's
way over my head I turn to the experts. Thanks alot, I'll give it a try.

Phil

"Bob Phillips" wrote:

Sub myAVerage()
Dim rng As Range
Dim iStart, iEnd

Set rng = Range("C7")
iStart = 3
iEnd = 7

Do
iStart = InputBox("Input first column (1-7)")
Loop Until iStart = "" Or (iStart 0 And iStart < 8)

If iStart < "" Then
Do
iEnd = InputBox("Input first column (1-7)")
Loop Until iEnd = "" Or (iEnd 0 And iEnd < 8)

myval = Application.Sum(rng(1, CLng(iStart)).Resize(, iEnd - iStart
+ 1)) / ((iEnd - iStart + 1) * 3)

MsgBox myval
End If

End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"phil-rge-ee" wrote in message
...
I have a spreadsheet that has weeks 1-9 (columns C-K). In each week is 3
numbers (rows 4-6). Those numbers get added together to get a total for

that
week (row 7).
I need help with creating the VB script that when run adds the totals
together and gives an average for a specified week range.

Example: user clicks a button and a dialog box comes up where they enter

in
the week range in textboxes. So textbox1.text could be 3 and textbox2.text
could be 7. Then the user clicks an ok button and the script runs. The

script
would add together the totals for week 3,4,5,6,7 (in row 7) then divide

that
sum by: number of weeks x 3 (in this case 15)
Another example: user enters in week 6 to week 9, they click ok and the
script runs. It would add the totals for week 6,7,8,9 then divide that sum
by: number of weeks x 3 (in this case 12)

The week range will be different all the time, depending on what specified
week average I need at that time. Can anyone help me with this?

Thanks for any help you can provide,
Phil




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
Average last 6 weeks and year before Nynke Excel Discussion (Misc queries) 2 August 6th 10 03:38 PM
Help Please: Need an Average for 16 Weeks according to Month drober Excel Worksheet Functions 2 June 9th 09 02:48 AM
Calculation based on numbers of weeks service WaqB Excel Discussion (Misc queries) 4 February 23rd 09 01:16 AM
I have 12 scores over 12 weeks . I want to average the highest 5 Directioneng Excel Worksheet Functions 1 August 18th 05 11:20 PM
calculate weeks from a start date ( not yr weeks) Todd F. Excel Worksheet Functions 6 November 27th 04 05:53 PM


All times are GMT +1. The time now is 04:09 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"