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: 5,934
Default Basic Looping

If I have interpreted your code correctly, these four lines of code should
replace ALL the code you posted (including that parts that would be covered
by the etc.)...

WeekTotalJan = 0
Cells(3 + Week, "K").Offset(0, 3 * (aMonth - 1)).Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan

--
Rick (MVP - Excel)



"ecce_ego" wrote in message
...
I have made a form that will enter customer data in a worksheet and
calculate
several things, including checking a date range and adding totals to a
table
of weekly totals for the month. The code I wrote works, but I am new to
programming and do not know how to create a more logically structured
program.

Here is a portion of the code I've written; how do I use a loop to
accomplish the same thing?

---------------------

If aMonth = "1" Then
If Week = "1" Then
WeekTotalJan = 0
Range("K4").Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan
Else
If Week = "2" Then
WeekTotalJan = 0
Range("K5").Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan
Else
If Week = "3" Then
WeekTotalJan = 0
Range("K6").Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan
Else
If Week = "4" Then
WeekTotalJan = 0
Range("K7").Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan
Else
If Week = "5" Then
WeekTotalJan = 0
Range("K8").Select
WeekTotalJan = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalJan
End If
End If
End If
End If
End If
Else
If aMonth = "2" Then
If Week = "1" Then
WeekTotalFeb = 0
Range("N4").Select
WeekTotalFeb = AmountDueTextBox.Value
ActiveCell.Value = ActiveCell.Value + WeekTotalFeb
Else
If Week = "2" Then..........etc....
--------------------------

It's really a pain to write all those ifs!


 
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
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
Looping...but why? cherrynich Excel Programming 2 May 12th 06 04:57 PM
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
Problem with basic looping and criteria Jeff Excel Programming 2 December 29th 04 10:05 PM
Looping Gusset Gadder Excel Programming 2 December 11th 04 09:16 PM


All times are GMT +1. The time now is 12:35 PM.

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"