Loop increment value

Recommended Posts

```For \$A1 = 12 To 11 + \$Total

For \$B1 = 1 To (\$oExcel.Application.Cells(\$A1,6).Value)   ; This value is from the Excel file. It can be from 1 - 9.

For \$N1 = 7 To ???  ; This is based on the value of \$B1 ((1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)

Send("-"& (\$oExcel.Application.Cells(\$A1,\$N1).Value) &"/"& (\$oExcel.Application.Cells(\$A1,\$N1+1).Value))
Sleep(400)
Send("{ENTER}")
Sleep(700)
Next
Next
Next```

I am not able to figure how to loop \$N1 as follows

If the Value of \$B1 = 1 then \$N1 = 7

If the Value of \$B1 = 2 then \$N1 = 17

If the Value of \$B1 = 3 then \$N1 = 27

If the Value of \$B1 = 4 then \$N1 = 37

The value of \$N1 comes from \$B1 where 1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)

Thank You

Share on other sites

I think you want to drop the third loop and use this instead:

`\$N1 = \$B1 * 10 - 3`

But I'd highly suggest looking into setting the formula/value of the cell instead of using Send. It's super effective

All my code provided is Public Domain... but it may not work.  Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Share on other sites

```\$step = 10
For \$N1 = 7 To (10 X (\$oExcel.Application.Cells(\$A1,2).Value)) Step \$step```

How to indicate the loop 'To' value as 10 x value extracted from a specific excel cell, and start from 7 and then increase the loop in multiples - 7, (10X2) = 20, (10X3) = 30, (10X4) = 40. But because we start from 7 and step up by 10, the loop counter would go 7, 17, 27, 37.....

Share on other sites

Hi, can you explain what you want to do ?

When you say:

Quote

But because we start from 7 and step up by 10, the loop counter would go 7, 17, 27, 37.....

Do you mean/want  that the loop counter should go in 7, 17, 27

or do you want that the loop counter should go 7, 10, 20, 30, 40, 50 ?

Some of my script sourcecode

Share on other sites

```\$iCount = (\$oExcel.Application.Cells(\$A1,6).Value)
\$step = 10
For \$N1 = 7 To 10 * \$iCount Step \$step
Send("-"& (\$oExcel.Application.Cells(\$A1,\$N1).Value) &"/"& (\$oExcel.Application.Cells(\$A1,\$N1+1).Value))
Sleep(400)
Send("{ENTER}")
Sleep(700)
Send("{ESC}")
Sleep(300)

Send (\$oExcel.Application.Cells(\$A1,\$N1+7).Value)
Sleep(400)
Send("{ENTER}")
Sleep(700)
Send("{ESC}")
Sleep(300)```

I think we got it to work.

1- So I wanted the script to read the data from cell (\$A1,6) to know how many times to loop.

2- If  the value in cell (\$A1,6) is 5, then the script will loop from 7 to 50 (10 X 5)

3- Because of the \$Step, it will jump 10 numbers. That means it will go 7, 17 (7+10), 27 (17+10), 37 (27+10), 47 (37+10)

4- The loop will stop at 47 since 50 is the end of loop and next loop counter value will go over 50

5- \$N1 starts from value 7 which make the script read cell value starting (\$A1,7)

We did it 🙂

Create an account

Register a new account

• Similar Content

• Help with delete row from array if value exist in cell

By kemo1987,

• 4 replies
• 899 views
• trying to make loop more efficient

By mmoalem,

• 4 replies
• 916 views
• Loop with multiple increment variables

By Vikramjeet,

• 0 replies
• 1,011 views
• Display loop count 1 2

By ssah8,

• 37 replies
• 7,686 views
• Make a loop run from 1 to 100 and wait for 10 first commands done then continue.

By ThePoro,

• 5 replies
• 2,194 views
×

• Wiki
• AutoIt Resources

• FAQ
×
• Create New...