Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Help with a loop

I am using Excel 97 and struggling to get the following
loop to work properly.

Can anyone assist me with where I am going wrong?

I want to pickup dates from one sheet and copy them also
as dates into another sheet but for some reason it
recognises that there is something in the cell but doesn't
pickup it's value!!

I have defined

StartDate & LastDate as Date
TotalDays as integer
Holiday as string

THE CODE
..............................................


Let A = 7
Let B = 7
Let C = 7
Let D = 7

' search for all sheets and get values
For Each asheet In ActiveWorkbook.Sheets

If asheet.Visible = True Then
sheetname = asheet.Name
Worksheets(sheetname).Activate


With ActiveSheet

EmployeeName = Cells(4, 1).Value
OfficeName = Cells(2, 2).Value
DeptName = Cells(2, 5).Value
FloorNo = Cells(3, 3).Value
DaysAvailable = Cells(31, 9).Value

If strOffice = "ALL" Then GoTo All
If OfficeName < strOffice Then GoTo Continue

All:
Do Until IsEmpty(asheet.Cells(A, 2))

StartDate = Cells(A, 2).Value
LastDate = Cells(B, 3).Value
TotalDays = Cells(C, 10).Value
HolDetails = Cells(D, 1).Value

' SUB TO MOVE VALUES TO LEAVE TABLE
DoMoveToLeaveTableDates

Let A = A + 1
Let B = B + 1
Let C = C + 1
Let D = D + 1

Loop

End With

Continue:

End If

Let A = 7
Let B = 7
Let C = 7
Let D = 7

Next asheet

.................................................. ..


Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with a loop

The obvious answer is that if OfficeName < strOffice, then your code to
copy the dates is never executed.

the second possible problem could be that the copying is being done in
DoMoveToLeaveTableDates

It is possible that this sub does not have visibility of your variables or
for some other reason does not successfully copy the values. Since you
only show a snippet of your code, and don't show this sub, it is impossible
to tell where the actual problem may lie. It could be as simple that
OfficeName and strOffice do not agree because one has an upper case letter
and the other doesn't.

Just above that IF test, you could put up a msgbox

msgbox OfficeName & " = " & strOffice & " = " & OfficeName = strOffice

or use the debugging tools to step through the code and watch the variable
values.

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
I am using Excel 97 and struggling to get the following
loop to work properly.

Can anyone assist me with where I am going wrong?

I want to pickup dates from one sheet and copy them also
as dates into another sheet but for some reason it
recognises that there is something in the cell but doesn't
pickup it's value!!

I have defined

StartDate & LastDate as Date
TotalDays as integer
Holiday as string

THE CODE
.............................................


Let A = 7
Let B = 7
Let C = 7
Let D = 7

' search for all sheets and get values
For Each asheet In ActiveWorkbook.Sheets

If asheet.Visible = True Then
sheetname = asheet.Name
Worksheets(sheetname).Activate


With ActiveSheet

EmployeeName = Cells(4, 1).Value
OfficeName = Cells(2, 2).Value
DeptName = Cells(2, 5).Value
FloorNo = Cells(3, 3).Value
DaysAvailable = Cells(31, 9).Value

If strOffice = "ALL" Then GoTo All
If OfficeName < strOffice Then GoTo Continue

All:
Do Until IsEmpty(asheet.Cells(A, 2))

StartDate = Cells(A, 2).Value
LastDate = Cells(B, 3).Value
TotalDays = Cells(C, 10).Value
HolDetails = Cells(D, 1).Value

' SUB TO MOVE VALUES TO LEAVE TABLE
DoMoveToLeaveTableDates

Let A = A + 1
Let B = B + 1
Let C = C + 1
Let D = D + 1

Loop

End With

Continue:

End If

Let A = 7
Let B = 7
Let C = 7
Let D = 7

Next asheet

.................................................. .


Mark



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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
How to loop saman110 via OfficeKB.com Excel Discussion (Misc queries) 4 July 25th 07 01:09 AM
if & Loop steven.holloway Excel Discussion (Misc queries) 5 July 20th 07 09:50 AM
do..loop Anna Excel Discussion (Misc queries) 6 June 20th 07 01:10 PM
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM


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

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"