looping excel rows and using individual columns as variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
itkbcores
Posts: 2
Joined: 26 Oct 2021, 15:28

looping excel rows and using individual columns as variables

26 Oct 2021, 15:35

I have a code I've been using for two years that uses an input box for the two variables I need (description and prodcode), but I'd like to put all my variables into a spreadsheet (column A and B) and have the code keep looping until it runs into a null row.

Code: Select all

^2::
Send, DD13
InputBox, description, Part Description, Enter the description of the part, 640, 480, , , , , , DIESEL 
InputBox, prodcode, PRODUCT CODE, Enter the product code, 640, 480, , , , , ,
if ErrorLevel
{
MsgBox, CANCEL was pressed.
Exit
}
Else
{
Send, {Enter}%description%{Enter}%description%{Enter}{Enter}A{Enter}{Enter}{Enter}P{Enter}{Enter}{Enter}{Enter}DETROIT{Enter}{Enter}DIESEL{Enter}{Enter}1{Enter}{Enter}{Enter}6{Enter}{Enter}12.9{Enter}%prodcode%{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}{Enter}Y{Enter}{Enter}{Enter}{Enter}{Enter}1{Enter}{F1}{Enter}
return
}
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26935
Joined: 09 Sep 2014, 18:38

Re: looping excel rows and using individual columns as variables

26 Oct 2021, 17:01

Code: Select all

F3::
XL := ComObjActive("Excel.Application"), sheet := XL.Application.ActiveSheet
Loop {
 description := sheet.Cells(A_Index, 1).Text, code := sheet.Cells(A_Index, 2).Text
 If (description > "")
  Send %code%: %description%`n
} Until (description = "")
Return
Or:

Code: Select all

F3::
XL := ComObjActive("Excel.Application"), used := XL.ActiveSheet.UsedRange
Loop, % used.Rows.Count
 Send % used.Cells(A_Index, 2).Text ": " used.Cells(A_Index, 1).Text "`n"
Return
itkbcores
Posts: 2
Joined: 26 Oct 2021, 15:28

Re: looping excel rows and using individual columns as variables

27 Oct 2021, 08:45

Brilliant! I used the first code and added other variables based on your example and it was perfect for my application.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 438 guests