Help adding a loop to this code

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bad husband
Posts: 54
Joined: 21 Oct 2017, 13:38

Help adding a loop to this code

17 Aug 2018, 22:02

I found this code from member Kon that I would like to use for a small script but I just can’t understand the looping of the scripts.

Is there a useful tutorial on creating loops for excel projects?

Here is the code. Basically I want it to go thru each neighboring columns D & E until there is a blank and stop the code

Code: Select all

 
;    Merge the contents of cells D2:E2
 
WorkBookPath := A_Desktop "\Book1.xlsx"                 ; store the path to the workbook
objExcel := ComObjCreate("Excel.Application")           ; create a handle to a new excel application
objWorkBook := objExcel.Workbooks.Open(WorkBookPath)    ; opens the existing excel table
objExcel.Visible := true                                ; make excel visible
 
objRange := objExcel.Worksheets(1).Range("D2:E2")       ; store a range object
for key, val in objRange   
    MergedVar .= key.Value
 
MsgBox, % "Merged contents of D2:E2 = " MergedVar
 
objRange.Value := ""        ; clear the contents of the range so no warning is shown when merging
objRange.Merge()            ; merge the range
MsgBox, Cells Merged
 
objExcel.Worksheets(1).Range("F2").Value := MergedVar
;objWorkBook.Save
;objExcel.Quit()
;objExcel := ""
;ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Mannaia666 and 407 guests