VBA Listbox: Check if listbox items are already in specified worksheet range and write listbox item in next empty cell -


title seems bit complicated, i'll try explaining steps (what want vba code do):

  1. read 1 list item list
  2. if item in 1st column (columns(1)) in worksheet, skip steps 3. , 4.
  3. if item not in 1st column (columns(1)) check first empty cell in column (reading top)
  4. when next empty cell has been found copy item not in column in empty cell
  5. proceed next item

what have far following code:

private sub tab1_done_button_click()     dim ws worksheet     dim integer     dim listitem variant        listitem = 0 me.tab1_product_picked.listcount - 1           'check if product there (dont't create duplicate)            = 4 400            if ws.cells(i, 1).value <> me.tab1_product_picked.list(listitem)                    'write in first empty cell in 1st column if not duplicate                    each cell in ws.columns(1).cells                        if isempty(cell) = true                             cell.value = me.tab1_product_picked.list(listitem)                             exit                        end if                    next cell                    exit              end if         next     next listitem end sub 

i have made logical mistake somewhere here, happens following:

i have product 3, product 5 , product 6 in first column. go listbox in form , after several actions end following items in listbox: product 3, product 6 , product 7. expect code transfer product 7 in next empty cell in 1st column, currenlty still transfers products listbox , after have in first column: product 3, product 5, product 6, product 3, product 6, product 7. means code able recognize empty cells in first row, able read data listbox, able copy data listbox , paste in empty cells desired, but unable check whether product listbox in 1 of cells in 1st column.

thank in advance advice on how fix part code needs check duplicates.

cheers , thanks!

i have rewrote code in way, supposed to. tested , works correctly:

range("a:a").select         listitem = 0 me.tab1_product_picked.listcount - 1                 if selection.find(what:=me.tab1_product_picked.list(listitem), lookin:=xlvalues) nothing                     each cell in columns(1).cells                         if isempty(cell) = true                             cell.value = me.tab1_product_picked.list(listitem)                             exit                         end if                     next cell                 end if         next listitem 

i'll leave here in case ever encounters same problem :)


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -