Help, need help for selecting different Excel cell with "+1" thingy.. or i don't know how to call it..

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Ram
Posts: 16
Joined: 13 Jan 2021, 10:56

Help, need help for selecting different Excel cell with "+1" thingy.. or i don't know how to call it..

Post by Ram » 14 Mar 2021, 18:37

Hello, i need help in Excel automation with autohotkey..

So i want to select "A1" cell in the 1st input, then for the 2nd, 3rd, and next input, i want to select the "A" cell +1,
so the "A" cell selected in the 2nd INPUT will be A2
the "A" cell selected in the 3nd INPUT will be A3, etc...

So it will be likely like this..

Code: Select all

INPUT1:
X=1

oExcel := ComObjActive("Excel.Application")
oExcel.Sheets("SHEET").Activate
oExcel.Range("A1").Select

goto, INPUTX:

INPUTX:
X = +1
oExcel := ComObjActive("Excel.Application")
oExcel.Sheets("SHEET").Activate
oExcel.Range("A(X)").Select
[Mod edit: [code][/code] tags added.]

but i don't know how to write it properly in AHK codes.... can somebody help me to solve this please? Thankyou very much...

User avatar
boiler
Posts: 16911
Joined: 21 Dec 2014, 02:44

Re: Help, need help for selecting different Excel cell with "+1" thingy.. or i don't know how to call it..

Post by boiler » 16 Mar 2021, 19:21

You posted in the v2 section of the forum, and based on your code and your prior posts, it looks like you are using v1 which is the latest official released version of AHK. AHK v2 is in the alpha testing phase. Anyway, continuing with your question...

You can increment X one of several ways, including X++, X += 1, or X := X + 1, but not X = +1.

See the script below for properly including the value of the variable X in your range definition.

There is no need to establish the oExcel object a second time. There is also no need for the goto where you have it, but maybe it's a placeholder for a larger script. However, I recommend against using goto in any of your scripts. It's generally not considered good programming practice.

Here is a working script:

Code: Select all

X := 1
oExcel := ComObjActive("Excel.Application")
oExcel.Sheets("SHEET").Activate
oExcel.Range("A1").Select

X += 1
oExcel.Range("A" . X).Select

Ram
Posts: 16
Joined: 13 Jan 2021, 10:56

Re: Help, need help for selecting different Excel cell with "+1" thingy.. or i don't know how to call it..

Post by Ram » 01 Apr 2021, 11:09

Thank you very much boiler for your help really appreciate it/

Post Reply

Return to “Ask for Help (v2)”