Excel COM: Column to the Right of Arbitrary Column Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
MaxAstro
Posts: 551
Joined: 05 Oct 2016, 13:00

Excel COM: Column to the Right of Arbitrary Column

14 Aug 2018, 11:58

Situation: I have a piece of data in a given column. The column might be one letter, or it might be two letters. I need to retrieve the data one column to the right. I'm at a bit of a loss. Next row is easy; just add one to the variable. But I can't seem to figure out next column.
awel20
Posts: 72
Joined: 19 Mar 2018, 14:09

Re: Excel COM: Column to the Right of Arbitrary Column  Topic is solved

14 Aug 2018, 12:51

You can use .Offset (https://msdn.microsoft.com/en-us/vba/ex ... erty-excel) or .Cells (https://msdn.microsoft.com/en-us/vba/ex ... erty-excel or https://msdn.microsoft.com/en-us/vba/ex ... erty-excel).

Simple example using the active cell. Excel must be running when you start the script then press Ctrl+1, 2 or 3.

Code: Select all

XL := ComObjActive("Excel.Application")
return

^1::
    MsgBox % XL.ActiveCell.Row "`n" XL.ActiveCell.Column
return

^2::
    Row := XL.ActiveCell.Row
    Col := XL.ActiveCell.Column
    Cell := XL.Cells(Row + 2, Col + 3)
    MsgBox % Cell.Address
return

^3::
    MsgBox % XL.ActiveCell.Offset(2, 3).Address
return

Return to “Ask For Help”

Who is online

Users browsing this forum: jackdunning, Yugo and 50 guests