Help with Excel Com

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Help with Excel Com

23 Mar 2018, 21:08

Hi,

I have a .txt file with many of the following value:
11111111111111 a1b2c3d4e5f6g ; There is 2 value separated by a space

And I have an Excel sheet with the same or different value in column A and B. It is the same lenght.

What I need to do is look into the .txt the first sequence of data (11111111111111) exist in the column A of Excel.

1-If it exist, it will check if there is something in the column B.
1-1If there is something in column B, we skip and check the second line of the .txt
1-2If its exist and there is nothing in the B, it get the second sequence of data (a1b2c3d4e5f6g) and paste it into the B column (same line as the found match)

2-If the first sequence of data (11111111111111) is not found in the column A, we add it in the next empty row in column A.

I do know the find COM: oWorkbook.Worksheets("Sheet1").Range("A:A").Find(Variable,,,lookat:=1).Row ; it will store 1 if the value is found in A:A

It is a little too tricky for me, is there gentlemen? :)
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Help with Excel Com

24 Mar 2018, 03:14

Try this. It will operate on the current open Excel file or, if it don't exist, it will open the desired workbook.

Code: Select all

Try
	XL := ComObjActive("Excel.Application")
catch {
	XL := ComObjCreate("Excel.Application")
	XL.Workbooks.Open(a_scriptdir "\Test00.xls") ; put your WorkBook full path name
	XL.Visible := true
}	
XLDOWN := -4121
str=
(
11111111111111 a1b2c3d4e5f6g
22222222222222 bsh446ta6sfs5
33333333333333 r5fad5t6gfcsb
44444444444444 o1iiu1827hhg1
)
loop, parse, str, `n
{
	Arr := StrSplit(a_Loopfield, " ")
	foundRow := XL.Worksheets(1).Range("A:A").Find(Arr[1],,,1).Row 	
	if (FoundRow) {
		if ( XL.Cells(foundRow,2).value = "")
			XL.Cells(foundRow,2).value := Arr[2]	
	} else {
		newRow := XL.Cells(1,1).End(XLDOWN).Row + 1
		XL.Cells(newRow,1).Value := Arr[1]
		XL.Cells(newRow,2).Value := Arr[2]
	}
}	
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, cleancode, norot41087, ntepa, Xeo786 and 116 guests