How to find multipal letters in a column in ms excel by these codes?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to find multipal letters in a column in ms excel by these codes?

10 Mar 2017, 11:46

Friends i have these codes by that i can find specific letter in the given range-

Code: Select all

f1::
 oExcel := ComObjActive("Excel.Application")
    oExcel.Range("b:b").Find("p", oexcel.activecell.entirerow.cells(1,2)).select 
	return
As in the above codes it finds letter p in column b in excel sheet. Now here i want that it should find either p or m in column b then what should be the codes? it tried to modify these codes in many ways like-

Code: Select all

f1::
 oExcel := ComObjActive("Excel.Application")
    oExcel.Range("b:b").Find("p" or "m", oexcel.activecell.entirerow.cells(1,2)).select
	return

Code: Select all

 oExcel := ComObjActive("Excel.Application")
    oExcel.Range("b:b").Find("p") or ("m", oexcel.activecell.entirerow.cells(1,2)).select 
	return

Code: Select all

 oExcel := ComObjActive("Excel.Application")
    oExcel.Range("b:b").Find("p", oexcel.activecell.entirerow.cells(1,2)).select  or oExcel.range("b:b").Find("m", oexcel.activecell.entirerow.cells(1,2)).select  
	return
But none of these codes are working as i want. please tell me what would be the right codes to do that. Thanks...
I don't normally code as I don't code normally.
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: How to find multipal letters in a column in ms excel by these codes?

10 Mar 2017, 11:56

I'm not sure if this will work, but this is the first thing I thought of.

Code: Select all

oExcel := ComObjActive("Excel.Application")
range := oExcel.Range("b:b")

if range.find("p") oexcel.activecell.entirerow.cells(1,2)).select
if range.find("a") oexcel.activecell.entirerow.cells(1,2)).select
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to find multipal letters in a column in ms excel by these codes?

10 Mar 2017, 12:31

Crashm87 wrote:I'm not sure if this will work, but this is the first thing I thought of.

Code: Select all

oExcel := ComObjActive("Excel.Application")
range := oExcel.Range("b:b")

if range.find("p") oexcel.activecell.entirerow.cells(1,2)).select
if range.find("a") oexcel.activecell.entirerow.cells(1,2)).select
thanks dear Crashm87 for your kind respose...but these codes are not excetly working as i want. infact i have already used these codes like this-

Code: Select all

f1::
 oExcel := ComObjActive("Excel.Application")
oExcel.Range("b:b").Find("p", oexcel.activecell.entirerow.cells(1,2)).select
oexcel.Range("b:b").Find("m", oexcel.activecell.entirerow.cells(1,2)).select
	return
I don't normally code as I don't code normally.
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: How to find multipal letters in a column in ms excel by these codes?

10 Mar 2017, 13:29

Try this, I tested it on a workbook of mine, and it selected the cell containing my search

Code: Select all

FilePath := "..."  ; ENTER WORKBOOK PATH HERE
oExcel := ComObjActive("Excel.Application")
oWorkbook := ComObjGet(FilePath)
dataBase := oWorkbook.WorkSheets("Sheet1")


InputBox, LookFor, Search, Enter Search Criteria
myRng := dataBase.Range["A:A"]


if	!c :=	myRng.Find(LookFor)
{
	MsgBox, , Warning, No matches found. 
}
else
{
c.select
}
User avatar
FanaticGuru
Posts: 1907
Joined: 30 Sep 2013, 22:25

Re: How to find multipal letters in a column in ms excel by these codes?

10 Mar 2017, 15:49

Code: Select all

Xl := ComObjActive("Excel.Application")
if (Xl.Range("B1").Value ~= "p|m")
	Xl.Range("B1").Select
else
{
	R1 := Xl.Columns("B").Find("p").Row
	R2 := Xl.Columns("B").Find("m").Row
	Xl.Range("B" Min(R1,R2)).Select
}
It is important to remember that the find method only finds the first cell that matches. So hopefully you are aware of that and truly just want the first cell that contains "p" or "m". Find will not select all cells that contain a certain string.

Also the find method does not allow for "or". You have to do two finds and then select the one with the smallest row number to get the first cell that has what you are looking for.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to find multipal letters in a column in ms excel by these codes?

11 Mar 2017, 12:04

FanaticGuru wrote:

Code: Select all

Xl := ComObjActive("Excel.Application")
if (Xl.Range("B1").Value ~= "p|m")
	Xl.Range("B1").Select
else
{
	R1 := Xl.Columns("B").Find("p").Row
	R2 := Xl.Columns("B").Find("m").Row
	Xl.Range("B" Min(R1,R2)).Select
}
It is important to remember that the find method only finds the first cell that matches. So hopefully you are aware of that and truly just want the first cell that contains "p" or "m". Find will not select all cells that contain a certain string.

Also the find method does not allow for "or". You have to do two finds and then select the one with the smallest row number to get the first cell that has what you are looking for.

FG

thanks dear fanaticguru...
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 122 guests