LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default I want to make one loop

I use the following to get totals of those who ate breakfast and those
who ate lunch on a given day and post those totals in another workbook
(and it works as written):

Workbooks.Open "foodcost"
ThisWorkbook.Activate
BreakfastTotal = 0 'is this necessary?
LunchTotal = 0 'or this?
For i = 1 To 2
Sheets(i).Activate
t1 = Sheets(i).Rows(2).Find(Date).Offset(Range("Attenda nce").Rows.Count +
1, 0).Value
If t1 = "" Then t1 = 0 'or this if no non-member ate breakfast?
BreakfastTotal = BreakfastTotal + t1
Next
For i = 3 To 4
Sheets(i).Activate
t2 = Sheets(i).Rows(2).Find(Date).Offset(Range("Attenda nce").Rows.Count +
1, 0).Value
If t2 = "" Then t2 = 0 'or this if no non-member ate lunch?
LunchTotal = LunchTotal + t2
Next
Sheets(5).Activate
Workbooks("foodcost.xls").Sheets(6).Columns(1).Fin d(Format(Date,
"d")).Offset(0, 1).Value = Total 'from earlier in the code
Workbooks("foodcost.xls").Sheets(6).Columns(1).Fin d(Format(Date,
"d")).Offset(0, 2).Value = BreakfastTotal
Workbooks("foodcost.xls").Sheets(6).Columns(1).Fin d(Format(Date,
"d")).Offset(0, 3).Value = LunchTotal

I can't help but think there's a way to combine the 2 For/Next loops into
a single loop.

What it does:
Sheets(1) contains members who ate breakfast
Sheets(2) contains non-members who ate breakfast
Sheets(3) contains members who ate lunch
Sheets(4) contains non-members who ate lunch
Sheets(5) contains total attendance
Range("Attendance") is unique for each sheet and works OK.

Loop 1 adds up total breakfasts served
Loop 2 adds up total lunches served

All '.Finds' locate current date in both workbooks
"foodcost" has numbers in ColA representing dates
Total attendance goes 1 cell to right of "d" into ColB
Total breakfasts goes 2 cells to right of "d" into ColC
Total lunches goes 3 cells to right of "d" into ColD

--
David
 
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
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
How to Make a Loop count by 1% not 1 MichaelC Excel Programming 8 June 12th 05 02:04 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Help with macro to make it loop through coloums R Krishna Excel Programming 0 July 29th 03 04:54 PM


All times are GMT +1. The time now is 02:16 AM.

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

About Us

"It's about Microsoft Excel"