Loop Break when copying an empty cell in Excel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
VV710
Posts: 8
Joined: 17 Feb 2017, 15:12

Loop Break when copying an empty cell in Excel

21 Feb 2017, 21:30

Hi Everyone,

Rather new to Scripting but really excited to use it properly.
I'm having a huge amount of trouble finding out how to break a loop that reaches an empty cell in excel.

This Script simply goes down a column, copies the cell, jumps to a search program, downloads the file and jumps back to excel.

This works correctly for everything i need, and loops great with no issues, except that i can not get it to break once it copies an empty cell.

I'd like it to loop infinitely until it copies an empty cell in Excel.

This is a slightly earlier draft of my script where I use AltTab instead of using WinActivate. But this one is definitely stable and worked great. But i need it to break at copying empty cell.

Please let me know if i can provide any more information!

F12::
Loop, 10
{
suspend
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep 100
Send, {Alt Up}
send, {Down}
send, ^c
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep, 100
Send, {Alt Up}
send, ^v
Sleep, 100
send, {Enter}
Sleep, 10000
Send, {Tab 6}
Sleep, 100
Send, {Down}
Sleep, 100
Send, +{F10}
Sleep, 100
Send, {Down}
Sleep, 100
Send, {Enter}
Sleep, 100
Send, {Enter}
Sleep, 10000
Send, {Tab 7}
}
Return
User avatar
boiler
Posts: 16919
Joined: 21 Dec 2014, 02:44

Re: Loop Break when copying an empty cell in Excel

21 Feb 2017, 22:18

There are a number of things I would do to make the script more reliable, but to add only what you asked:

Code: Select all

F12::
Loop
{
suspend
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep 100
Send, {Alt Up}
send, {Down}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "")
	break
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep, 100
Send, {Alt Up}
send, ^v
Sleep, 100
send, {Enter}
Sleep, 10000
Send, {Tab 6}
Sleep, 100
Send, {Down}
Sleep, 100
Send, +{F10}
Sleep, 100
Send, {Down}
Sleep, 100
Send, {Enter}
Sleep, 100
Send, {Enter}
Sleep, 10000
Send, {Tab 7}
}
Return
VV710
Posts: 8
Joined: 17 Feb 2017, 15:12

Re: Loop Break when copying an empty cell in Excel

22 Feb 2017, 14:36

Hmm this didn't work for me even with just using your code rather then modifying mine.

It doesn't break the Loop.

From what I've been able to figure out online, the main reason its so difficult is because a Blank cell in Excel is not technically actually blank or empty. It has some data in it which is why I'm having difficulties with this.

Thank you for your Help!
User avatar
boiler
Posts: 16919
Joined: 21 Dec 2014, 02:44

Re: Loop Break when copying an empty cell in Excel

22 Feb 2017, 14:52

That makes sense, but this should work then:

Code: Select all

F12::
Loop
{
suspend
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep 100
Send, {Alt Up}
send, {Down}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
	break
Send, {Alt Down}
Sleep 100
Send, {Tab}
Sleep, 100
Send, {Alt Up}
send, ^v
Sleep, 100
send, {Enter}
Sleep, 10000
Send, {Tab 6}
Sleep, 100
Send, {Down}
Sleep, 100
Send, +{F10}
Sleep, 100
Send, {Down}
Sleep, 100
Send, {Enter}
Sleep, 100
Send, {Enter}
Sleep, 10000
Send, {Tab 7}
}
Return
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Loop Break when copying an empty cell in Excel

22 Feb 2017, 14:53

I'm just going to leave this here in case you are interested in going the more-reliable route that boiler alluded to.
https://autohotkey.com/boards/viewtopic ... 48#p112648
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Loop Break when copying an empty cell in Excel

22 Feb 2017, 14:56

VV710 wrote:Hmm this didn't work for me even with just using your code rather then modifying mine.

It doesn't break the Loop.

From what I've been able to figure out online, the main reason its so difficult is because a Blank cell in Excel is not technically actually blank or empty. It has some data in it which is why I'm having difficulties with this.

Thank you for your Help!
Blank cell copied to clipboard actually contains carriage return and linefeed. You have to remove those.

Code: Select all

send ^{c}
str := StrReplace(Clipboard, "`r`n")
if(str == "") {
	Break
}
If you want to improve your script, you could have a look at ComObject for the proper way to handle excel documents.
Here's a simple example from another post : https://autohotkey.com/boards/viewtopic ... 99#p133199
VV710
Posts: 8
Joined: 17 Feb 2017, 15:12

Re: Loop Break when copying an empty cell in Excel

22 Feb 2017, 15:25

Awesome!

This worked:
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break

I wasn't to far off with previous attempts but its really nice to have a working example to learn from.

I know I've got a LOT to learn and I've bookmarked your guys recommendations.

Thank you all!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ArkuS, mikeyww, Nerafius, sofista and 110 guests