excel - How to search a row for a string and then select the column of that string in VBA -


i'm working in vba trying select column based on occurrence of string in first row of excel spreadsheet. first, trying code search term "type" in first row of spreadsheet, , select entire "type" column. there i've been trying set column variable can call later on in code. sorry i'm not allowed post code i've been working work , not allowed.

ok, here's code have far. searches first row "type" , finds cell , selects it. i'm having trouble tying assign variable mycol entire column. keep getting "object doesn't support property or method error". sorry if obvious fix, i'm new vba.

function colsearch() integer  sheets("cs-crm raw data").select sheets("cs-crm raw data").unprotect  dim mycol range      cells.find(what:="type", after:=activecell, lookin:=xlformulas, lookat _         :=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:= _         false, searchformat:=false).activate     set mycol = activecell.enitrecolumn  colsearch = mycol  end function   

edit: ok here's edited code searching columns, selecting 1 labelled type, , setting equal variable. "object variable or block variable not set" error every time run it.

function colsearch() range  sheets("cs-crm raw data").select sheets("cs-crm raw data").unprotect  dim mycol range  mycol = worksheets("cs-crm raw data").cells.find(what:="type", after:=activecell, lookin:=xlformulas, lookat _     :=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:= _         false, searchformat:=false).column  mycol = colsearch  end function 

this solution worked me:

function colsearch2() integer colsearch2 = worksheets("cs-crm raw data").cells.find(what:="type", after:=activecell, lookin:=xlformulas, lookat _     :=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, matchcase:= _         false, searchformat:=false).column         end function 

the problem in using "entirecolumn".

according documentation, "returns range object represents entire column (or columns) containing specified range. read-only.", not column index.

http://msdn.microsoft.com/en-us/library/aa199727(v=office.10).aspx

edit: saw edit in main thread. type mismatch return range object integer.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -