VBA Getting data from multiselect listbox and saving them in other excel file in column with today date -
firstly tell trying , have done. got 2 files: mss - data listbox , want have output of selected items in listbox , second have userform. accomplish getting data listbox , multiselecting it:
private sub userform_initialize() on error goto userform_initialize_err dim cnn new adodb.connection dim rst new adodb.recordset dim integer cnn.open "provider=microsoft.ace.oledb.12.0;;" & _ "data source=c:\users\plkmxm08\desktop\mms.xlsm;" & _ "extended properties=""excel 12.0 xml;hdr=yes;"";" rst.open "select [line], [task] fff order [line];", _ cnn, adopenstatic rst.movefirst = 0 me.listbox1 .clear .additem .list(i, 0) = rst![line] .list(i, 1) = rst![task] = + 1 rst.movenext loop until rst.eof end userform_initialize_exit: on error resume next rst.close cnn.close set rst = nothing set cnn = nothing exit sub userform_initialize_err: msgbox err.number & vbcrlf & err.description, vbcritical, "error!" resume userform_initialize_exit end sub
it's working fine except problem heading. when change in listbox properties columnheads true there blank space. selected area fff heading. can live without it.
i big problem getting selected data values. in mss file there 2 important columns: line , task, after columns date in format yyyy/mm/dd.
so what is: when value in listbox selected click on commandbutton. excel search today's date in mss file , in columns line , task search text it's same selected in listbox. when finds 2 values: in column correct date , row correct value write "ok" , delete values listbox.
what important: values have been checked day should not imported listbox opening of excel file. after 6 every day, program should import again.
it's complicated hope understand meant.
i find way want have troubles 1 thing. here code:
`private sub commandbutton1_click() dim ldate date dim cnn new adodb.connection dim rst new adodb.recordset dim litem long, lrows long, lcols long dim bselected boolean dim lcolloop long, ltransferrow long dim val variant dim mdate date if time > timevalue("00:00:00") , time < timevalue("06:00:00") ldate = dateadd("d", -1, now) else ldate = end if mdate = datevalue(ldate) cnn.open "provider=microsoft.ace.oledb.12.0;;" & _ "data source=c:\users\plkmxm08\desktop\mms.xlsm;" & _ "extended properties=""excel 12.0 xml;hdr=yes;"";" rst.open "select [line], [task], [frequency] button order [task];", _ cnn, adopenstatic lcols = listbox1.columncount - 1 lrows = listbox1.listcount - 1 'ensure have @ least 1 row selected litem = 0 lrows 'at least 1 row selected if listbox1.selected(litem) = true 'boolean flag bselected = true 'exit loop exit end if next @ least 1 row selected if bselected = true litem = 0 lrows if listbox1.selected(litem) = true 'row selected 'loop through columns of selected row lcolloop = 1 lcols 'transfer selected row relevant row of transfer range val = listbox1.list(litem, lcolloop) rst.find "task = '" & val & "'" listbox1.selected(litem) = false next lcolloop end if next end if end sub`
so if check value in listbox find value in different excel file. problem need row index of cell , column index today's date. thankful if shows me right direction.
Comments
Post a Comment