excel - Using .Find() to find specific text in column -


i'm having trouble making sure code uses end user inputs find set of data pertaining value , continues code there. example, if user input "v-" prefix tag number, in theory cell a7 should selected after code complete. however, code proceeds run line "msgbox "no blank cell found below tag number prefix " & str & ".", vbexclamation" , select cell a3 due fact contains "v-" in cell. tried changing matchcase true did not help. not want entered value case sensitive.

enter image description here

code being used:

private sub worksheet_activate() dim msg string dim cell range dim str string, firstcell string  msg = "would find next available tag number?" result = msgbox(msg, vbyesno) if result = vbyes str = application.inputbox("enter tag number prefix ", "prefix tag number") if str = "" exit sub if right(str, 1) <> "-" str = str & "-" range("a:a") set cell = .find(str, lookat:=xlpart, matchcase:=false) if not cell nothing     firstcell = cell.address             if cell.offset(1, 0) = ""             cell.offset(1, 0).select             exit sub         elseif instr(lcase(cell.offset(1, 0)), lcase(str)) = 0             cell.select             msgbox "no blank cell found below tag number prefix " & str & ".", vbexclamation             exit sub         end if         set cell = .findnext(cell)     loop while not cell nothing , firstcell <> cell.address end if end else cancel = true end if end sub 

if want find cells content begins (e.g.) "v-"

set cell = .find(str & "*", lookat:=xlwhole, matchcase:=false) 

for data below:

sub tester()     activesheet.columns(1)          debug.print .find("c-" & "*", lookat:=xlwhole, _                                       matchcase:=false).address() '>> $a$3         debug.print .find("v-" & "*", lookat:=xlwhole, _                                       matchcase:=false).address() '>> $a$5      end end sub 

enter image description here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -