473,473 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with a For Next Loop

I have a routine in Access that loops through an Excel workbook and
executes code base on the worksheet name.

If the worksheet name contains the word 'Stats' than that is a sheet I
want to read (the code).

However, I want to process the company level first because I am going
to need to compare the company stats with those of the individual
agency stats.

Here is the code I have:

bolCompanyDone = True
For Each oXlSheet In oXlBook.Worksheets

If InStr(1, oXlSheet.Name, "Stats", vbTextCompare) 0 Then
If bolCompanyDone = False Then
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
0 Then
'Subroutine
bolCompanyDone = True
Else ' Sheet Not The Company One - Get Next Sheet
End If
Else
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
= 0 Then
'Subroutine (dont want to process company here - its been
done already)
End If
End If
Else ' Name in Worksheet Not Stats
End If

Next oXlSheet

The problem I am having is that once the company is done - I need to
reset the For Next loop and basically start over since the Overall
Stats workbook can be anywhere in the sheets. If I dont restart the
For Next - then I may have already skipped worksheets that I do want to
process.

Now the easy way to solve this is to have two for next loops - One to
first handle the company and the second to handle all the others.

Is that my answer or is there a better way to do this?

Thanks!

Sep 15 '06 #1
2 1594

BerkshireGuy wrote:
I have a routine in Access that loops through an Excel workbook and
executes code base on the worksheet name.

If the worksheet name contains the word 'Stats' than that is a sheet I
want to read (the code).

However, I want to process the company level first because I am going
to need to compare the company stats with those of the individual
agency stats.

Here is the code I have:

bolCompanyDone = True
For Each oXlSheet In oXlBook.Worksheets

If InStr(1, oXlSheet.Name, "Stats", vbTextCompare) 0 Then
If bolCompanyDone = False Then
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
0 Then
'Subroutine
bolCompanyDone = True
Else ' Sheet Not The Company One - Get Next Sheet
End If
Else
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
= 0 Then
'Subroutine (dont want to process company here - its been
done already)
End If
End If
Else ' Name in Worksheet Not Stats
End If

Next oXlSheet

The problem I am having is that once the company is done - I need to
reset the For Next loop and basically start over since the Overall
Stats workbook can be anywhere in the sheets. If I dont restart the
For Next - then I may have already skipped worksheets that I do want to
process.

Now the easy way to solve this is to have two for next loops - One to
first handle the company and the second to handle all the others.

Is that my answer or is there a better way to do this?

Thanks!
It's not entirely clear what you are trying to do, but why don't you
just set oXlSheet to the Overall Stats sheet in the first place? If
you know the sheet you want to perform the subroutine on is always
called "Overall Stats" it should work.

Set oXISheet = oXlBook.Worksheets("Overall Stats")
' subroutine

You might need to wrap a for..next around the subroutine if you have
multiple companies, but without the subroutine code I can't really tell
what you're trying to do.

Sep 15 '06 #2
Sorry about not being clear. I was in a crisis mode at the time. :)

There is a company sheet and then multiple agencies. I just had two
for next loops - One to first check for the company and then the second
to handle everything else. Each uses the same subroutine.

I was trying to get fancy with one for next loop with many if then
statements.

Thanks!

Wolf wrote:
BerkshireGuy wrote:
I have a routine in Access that loops through an Excel workbook and
executes code base on the worksheet name.

If the worksheet name contains the word 'Stats' than that is a sheet I
want to read (the code).

However, I want to process the company level first because I am going
to need to compare the company stats with those of the individual
agency stats.

Here is the code I have:

bolCompanyDone = True
For Each oXlSheet In oXlBook.Worksheets

If InStr(1, oXlSheet.Name, "Stats", vbTextCompare) 0 Then
If bolCompanyDone = False Then
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
0 Then
'Subroutine
bolCompanyDone = True
Else ' Sheet Not The Company One - Get Next Sheet
End If
Else
If InStr(1, oXlSheet.Name, "Overall Stats", vbTextCompare)
= 0 Then
'Subroutine (dont want to process company here - its been
done already)
End If
End If
Else ' Name in Worksheet Not Stats
End If

Next oXlSheet

The problem I am having is that once the company is done - I need to
reset the For Next loop and basically start over since the Overall
Stats workbook can be anywhere in the sheets. If I dont restart the
For Next - then I may have already skipped worksheets that I do want to
process.

Now the easy way to solve this is to have two for next loops - One to
first handle the company and the second to handle all the others.

Is that my answer or is there a better way to do this?

Thanks!

It's not entirely clear what you are trying to do, but why don't you
just set oXlSheet to the Overall Stats sheet in the first place? If
you know the sheet you want to perform the subroutine on is always
called "Overall Stats" it should work.

Set oXISheet = oXlBook.Worksheets("Overall Stats")
' subroutine

You might need to wrap a for..next around the subroutine if you have
multiple companies, but without the subroutine code I can't really tell
what you're trying to do.
Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: tym | last post by:
HELP!!! I'm going round the twist with this... I have a VB6 application which is using DAO to access a database (Please - no lectures on ADO, I know what I'm doing with DAO!!) Ok, problem...
6
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
1
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name....
1
by: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
14
by: bcap | last post by:
Hello, I really would apprciate help! =) What I want to do is be able to change the status of mulitple records using a drop down and a checkbox. I have a drop down called "ChangeStatus"...
2
by: IdlePhaedrus | last post by:
Hi, I have a FFT routine that I converted from C++ to VB in a module as follows: Const M_PI = 3.1415926535897931 ' Fast Fourier Transform Public Sub FFT(ByRef rex() As Single, ByRef imx() As...
0
by: LanaR | last post by:
Hello, one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql....
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.