excel vba - VBA - Open form within loop then wait for OK click -
i have script checks new shops in sheet. if finds new shop should open form , prompt user select shop category , click ok. when the user clicks ok value dropdown should selected , form closes , loop continues.
the form calles "shopkat"
this how works:
for = lbound(distshops) ubound(distshops) if not isempty(distshops(i)) curcell = getrows curshop = distshops(i) findout = checkifinsheet(curshop) if findout = false cells(curcell + 1, 1) = curshop 'show form shopkat.show vbmodal 'shop current shop shopkat.shop.caption = curshop 'get value combo cells(curcell + 1, 2) = shopkat.shopkatcombo.value 'if user click ok continue end if end if next
could help. lot!
//////////////////////////// updated /////////////////////////////// module1:
public curcell long dim ws worksheet
form shopkat:
private sub shopkatok_click() if not shopkat.shopkatcombo.value = "" ws.cells(curcell + 1, 2) = shopkat.shopkatcombo.value unload me end if end sub
loop sheet(shopcategories)
set ws = thisworkbook.sheets("shopcategories") = lbound(distshops) ubound(distshops) if not isempty(distshops(i)) curcell = getrows() curshop = distshops(i) findout = checkifinsheet(curshop) if findout = false shopkat.shop.caption = curshop 'show form shopkat.show if not isempty(cells(curcell + 1, 2).value) ws.cells(curcell + 1, 1) = curshop end if end if end if next
ok this. (untested)
a) insert module , paste these lines
public curcell long dim ws worksheet
b) next in userform's ok
button paste code
private sub commandbutton1_click() ws.cells(curcell + 1, 2) = shopkat.shopkatcombo.value unload me end sub
c) , lastly amend above code this
sub sample() ' '~~> rest of code ' '~~> change applicable set ws = thisworkbook.sheets("sheet1") = lbound(distshops) ubound(distshops) if not isempty(distshops(i)) curcell = getrows curshop = distshops(i) findout = checkifinsheet(curshop) if findout = false ws.cells(curcell + 1, 1) = curshop shopkat.shop.caption = curshop 'show form shopkat.show '<~~ no need mention vbmodal. default end if end if next ' '~~> rest of code ' end sub
Comments
Post a Comment