If/else/loop troubles

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
yee0890
Posts: 1
Joined: 28 Jun 2020, 18:49

If/else/loop troubles

28 Jun 2020, 21:19

Hi all, I'm new to AHK, and have been browsing and searching this past day to find a solution to my problem. What I'm trying to achieve is simple: if an Excel cell value is 2, move down. If value is not 2, write 2, move down. Repeat these steps 10 times, and spit out a message "end of loop". What am I doing wrong?

Code: Select all

#s:: 
xl := ComObjActive("Excel.Application")
cellvalue :=xl.activecell.value
loop, 10
{
if (cellvalue = 2)
{
Sleep, 500
Send, {Enter}
Sleep, 500
}
else
{
Send, 2
Sleep, 500
Send, {Enter}
}
}
msgbox, end of loop
Return
Last edited by lexikos on 28 Jun 2020, 22:53, edited 1 time in total.
Reason: code tags
Spark
Posts: 80
Joined: 04 Jan 2017, 02:22

Re: If/else/loop troubles

28 Jun 2020, 21:50

maybe something like this?

Code: Select all

#s::
	xl := ComObjActive("Excel.Application")
	loop, 10
	{
		cellvalue :=xl.activecell.value
		if (cellvalue = 2)
			xl.ActiveCell.Offset(1,0).Select ; Move Down
		else
		{
			xl.activecell.value := 2	; Change number "2"
			xl.ActiveCell.Offset(1,0).Select	; Move Down
		}
	}
	msgbox, end of loop
return
reff :
Excel Tutorials and XL Function library
Basic Ahk_L COM Tutorial for Excel
HTH

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Kodakku, Noesis and 377 guests