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

Get help with using AutoHotkey and its commands and hotkeys
Posts: 557
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.
Posts: 211
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")

    MsgBox % XL.ActiveCell.Row "`n" XL.ActiveCell.Column

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

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

Return to “Ask For Help”

Who is online

Users browsing this forum: djuga, Jayinem, songdg and 29 guests