excel - How to work with arrays and display them in a MsgBox VBA -


i need write sub take single argument input box searches stock price in list. sub searches down list of prices "b3:b20" , when finds first price exceeds price displays date displays in column next in column in msgbox. code have far having trouble figuring out how display corresponding data price found:(i believe problem has array created)

sub recordhigh1() dim searchprice currency dim rng range dim date1() string dim price() string dim ndates integer dim integer    wsdata.range("a3") ndates = range("a3", range("a3").end(xldown).value) redim date1(1 ndates) redim price(1 ndates) = 1 ndates     date1(i) = .offset(i, 0).value     price(i) = .offset(i, 1).value next end   searchprice = inputbox("enter price") set rng = range("b3", range("b3").end(xldown).address)  each cell in rng if cell.value > searchprice msgbox "the first date waltech stock price exceeded " & searchprice & " & date(i) =.offset(i, 0).value & " else msgbox "waltech stock has not exceeded price" end if next    end sub 

option explicit  sub recordhigh1() dim searchprice currency dim rng range dim date1() string dim price() string dim ndates long dim long '<~~ better use long type instead of integer  dim cell range   'with wsdata.range("a3")'<~~ wsdata not defined. or public variable? activesheet.range("a3") '<~~ otherwise set specific sheet: worksheets("mysheet").range("a3")     ndates = .range(.cells, .range("a3").end(xldown)).rows.count     redim date1(1 ndates)     redim price(1 ndates)     .range("a3")         = 1 ndates             date1(i) = .offset(i, 0).value             price(i) = .offset(i, 1).value         next '<~~ better type variable want iterate on     end end   searchprice = inputbox("enter price") set rng = activesheet.range("b3", activesheet.range("b3").end(xldown).address)'<~~ better add sheet reference (activesheet or worksheets("mysheet") or wsdata, latter once define it)   each cell in rng     if cell.value > searchprice         msgbox "the first date waltech stock price exceeded " & searchprice & " " & cell.offset(, -1)     else         msgbox "waltech stock has not exceeded price"     end if next cell '<~~ better type variable want iterate on  end sub 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo