Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Next Issue


Hi,

I am having an issue with a For Next loop where the current loop value
seems to be incrementing before getting to "Next".

Basically I want to loop through a number of periods (months) picking
up any rows that have a date that falls within the current period. The
code seems to work fine but for some reason it jumps from X1 = 1 to X1
= 2 or X1 = 3 before getting to Next - which means it is missing
picking up any data for those months.

Any ideas?

Thanks

My Code ---

For X1 = 1 To cboPeriods

If Not IsEmpty(ActiveCell.Value) Then

Date3 = DateAdd("m", 1, Date2)
Date4 = DateAdd("d", -1, Date3)

Do Until IsEmpty(ActiveCell.Value)

Date1 = ActiveCell.Value

If Date1 = Date2 And Date1 < Date4 Then
dblThisJob = ActiveCell.Offset(0, 3).Value
Call PerformCalc(Date1, X1, ActiveCell.Value, dblThisJob)
End If

ActiveCell.Offset(1, 0).Select
Loop

Else

' ## due to either there being no job/change requests or the first
job/change request
' ## is listed in cell 'A3'
MsgBox "Error: There is no Job/Change Request listed in cell 'A2'.
There must be a value in this first cell", vbCritical

End If

Date2 = DateAdd("m", 1, Date2)
Application.Goto (Worksheets("ChangeRequests").Range("A2"))

Next X1

End Code ---


--
darkman
------------------------------------------------------------------------
darkman's Profile: http://www.excelforum.com/member.php...o&userid=34689
View this thread: http://www.excelforum.com/showthread...hreadid=544554

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default For Next Issue

Hi,

you need to rearange your code to get rid of "ActiveCell.Offset(1,
0).Select" in the inner loop.

Regards,
Ivan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default For Next Issue

But you probably need to put it in the outer loop to ensure that the loop
moves on.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Ivan Raiminius" wrote in message
oups.com...
Hi,

you need to rearange your code to get rid of "ActiveCell.Offset(1,
0).Select" in the inner loop.

Regards,
Ivan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default For Next Issue

You don't use X1 except in the call to PerformCalc. If it is getting changed
prematurely, it would be in PerformCalc. Possibly pass it byVal instead of
the default byRef.

--
Regards,
Tom Ogilvy


"darkman" wrote:


Hi,

I am having an issue with a For Next loop where the current loop value
seems to be incrementing before getting to "Next".

Basically I want to loop through a number of periods (months) picking
up any rows that have a date that falls within the current period. The
code seems to work fine but for some reason it jumps from X1 = 1 to X1
= 2 or X1 = 3 before getting to Next - which means it is missing
picking up any data for those months.

Any ideas?

Thanks

My Code ---

For X1 = 1 To cboPeriods

If Not IsEmpty(ActiveCell.Value) Then

Date3 = DateAdd("m", 1, Date2)
Date4 = DateAdd("d", -1, Date3)

Do Until IsEmpty(ActiveCell.Value)

Date1 = ActiveCell.Value

If Date1 = Date2 And Date1 < Date4 Then
dblThisJob = ActiveCell.Offset(0, 3).Value
Call PerformCalc(Date1, X1, ActiveCell.Value, dblThisJob)
End If

ActiveCell.Offset(1, 0).Select
Loop

Else

' ## due to either there being no job/change requests or the first
job/change request
' ## is listed in cell 'A3'
MsgBox "Error: There is no Job/Change Request listed in cell 'A2'.
There must be a value in this first cell", vbCritical

End If

Date2 = DateAdd("m", 1, Date2)
Application.Goto (Worksheets("ChangeRequests").Range("A2"))

Next X1

End Code ---


--
darkman
------------------------------------------------------------------------
darkman's Profile: http://www.excelforum.com/member.php...o&userid=34689
View this thread: http://www.excelforum.com/showthread...hreadid=544554


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Next Issue


Ivan Raiminius Wrote:
Hi,

you need to rearange your code to get rid of "ActiveCell.Offset(1,
0).Select" in the inner loop.

Regards,
Ivan


If I remove that code my function ceases to be of any use...

Why is the offset causing the X1 to increment?

Any suggestions of a better way to do it?


--
darkman
------------------------------------------------------------------------
darkman's Profile: http://www.excelforum.com/member.php...o&userid=34689
View this thread: http://www.excelforum.com/showthread...hreadid=544554



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default For Next Issue

Hi,

offset isn't causing X1 to increment.

I couldn't test your code, so I couldn't see what really happens.
Probably you are sure that X1 changes? In your code I can see that
activecell.value (in the call to PerformCalc) changes, because of
"ActiveCell.Offset(1, 0).Select" in the inner loop. X1 must be changed
somewhere else then in code you posted (because it is not used except
in the call to PerformCalc).

Regards,
Ivan

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
Another #DIV/0! Issue Debbie Excel Worksheet Functions 12 February 26th 08 09:39 PM
Issue [email protected] Excel Discussion (Misc queries) 1 July 21st 06 05:13 AM
IIF issue Scott Excel Worksheet Functions 6 December 18th 05 07:55 PM
please help with this issue Overbey New Users to Excel 6 January 4th 05 05:02 PM
xla add in issue PM Excel Programming 5 October 6th 04 07:12 AM


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