# Efficient way to for a For loop using two numbers?

## Recommended Posts

Sorry for the poor title, I couldn't think of a better way to handle this.

Alright, so I have an array that has 24 items. I need to plug this into an Excel sheet.

The problem is, the Excel cells start at 8. So I can't do a simple For loop using \$i as the count to move through the cells.

So I need a way to fill in the cells like this.

```For \$i = 1 To 24
_ExcelWriteCell(\$oExcel, \$InitialVolts[\$i][1], 8, 2) ; Write Customer
Next```

But where the 8 goes up +1 each time. I assume with some logical math I could get this to work.. but I hate math and I figured there might be a more efficient way to handle it.

Thanks!

Solved using

```\$Count = 7

For \$i = 1 To 24
\$Count += 1
_ExcelWriteCell(\$oExcel, \$InitialVolts[\$i][1], \$Count, 2) ; Write Customer
Next```
Edited by Damein

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

##### Share on other sites

Yeah, I actually thought of that after I typed it out and posted... I should really stop doing that, I write it out and then it comes to me how I should do it.

Thanks for the quick reply though

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

##### Share on other sites

What's wrong with this?

```For \$i = 1 To 24
_ExcelWriteCell(\$oExcel, \$InitialVolts[\$i][1], 7 + \$I, 2) ; Write Customer
Next```

The first time through the number starts at 8 and goes up by one each time it runs through the loop.

Or even like this for the anti-magic-number crowd

```\$Count = 7
For \$i = 1 To 24
_ExcelWriteCell(\$oExcel, \$InitialVolts[\$i][1], \$Count + \$I, 2) ; Write Customer
Next```

Either way, you're using the loop counter as the number to be added to the initial number, without an unneeded increment statement.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

## Create an account

Register a new account

×

• Wiki

• Back

• Git