excel vba - Turn 3 listboxes into 1 3-column listbox? -


the following code searches column a(sorted) item# , each time finds it, corresponding b, c & d column entered 3 listboxes. use 3-column listbox. help?

private sub cmdsearch_click()        dim response long     dim notfound integer     dim arr variant     dim long     dim str1 string, str2 string, str3 string      notfound = 0      activeworkbook.sheets("items").activate      response = val("0" & replace(txtitemnumber.text, "-", ""))      if response <> false          activesheet             arr = .range("a2:d" & .cells(.rows.count, "a").end(xlup).row)         end          = 1 ubound(arr)             if arr(i, 1) = response                 str1 = iif(str1 = "", arr(i, 2), str1 & "|" & arr(i, 2))                 str2 = iif(str2 = "", arr(i, 3), str2 & "|" & arr(i, 3))                 str3 = iif(str3 = "", arr(i, 4), str3 & "|" & arr(i, 4))             end if         next          if str1 = ""             msgbox "item number not found!", vbexclamation             notfound = 1         else             frame1.visible = true             listbox1.list = split(str1, "|")             listbox2.list = split(str2, "|")             listbox3.list = split(str3, "|")         end if      end if  end sub 

thanks help...

this should it:

change:

    if str1 = ""         msgbox "item number not found!", vbexclamation         notfound = 1     else         frame1.visible = true         listbox1.list = split(str1, "|")         listbox2.list = split(str2, "|")         listbox3.list = split(str3, "|")     end if 

to:

if str1 = ""   msgbox "item number not found!", vbexclamation   notfound = 1 else   frame1.visible = true   listbox1.clear 'to avoid errors   listbox1.columncount = 3    = 0 ubound(split(str1, "|"))     listbox1.additem split(str1, "|")(i)     listbox1.list(i, 1) = split(str2, "|")(i)     listbox1.list(i, 2) = split(str3, "|")(i)   next end if 

hint: may change columnwidths

however... leave work, suggest merge arr-part... using solution waste :d


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -