Excel VBA User form entry to a specific range inside worksheet -


so trying have user input information , put information in specific range based on values in dropdown list selected. example, selected monday, want information go in range a1:a12, if select tuesday go range g1:g12.

also, if range full data, i'd tell user full. not have example code, here psuedo-code example

private sub cbsubmit_click()     range("a2").select     activecell.end(xldown).select     lastrow = activecell.row     msgbox lastrow         if combobox1.value = "monday"         cells(lastrow + 1, 1).value = tb1.text         cells(lastrow + 1, 2).value = tb2.text     end if     if combobox1.value = "tuesday"         range("g2").select         activecell.end(xldown).select         lastrow2 = activecell.row         cells(lastrow2 + 1, 1).value = tb1.text         cells(lastrow2 + 1, 2).value = tb2.text     end if end sub 

also, in above code, there better way find last cell in range blank? 1 works if there data in range , that's not case. , check sort of counta or see if range full of data. in advance!

i answer can demonstrate code better.

as said in comments, if want check each value in range, can this:

dim c each c in range("a1:a10") 'whatever range check     if c <> vbnullstring         'found data - not empty         exit     end if next 

if you're checking 2 cells looks are, should use:

if cells(lastrow2 + 1, 1) <> vbnullstring , cells(lastrow2 + 1, 2) <> vbnullstring 

if want add data bottom of list, code getting last row , adding ... each time call this:

activecell.end(xldown).select lastrow2 = activecell.row 

it getting last row , rest of code adds end.

one more thing. should replace this:

range("g2").select activecell.end(xldown).select lastrow2 = activecell.row 

with this:

lastrow2 = range("g2").end(xldown).row 

you should avoid using select possible.

in experience, necessary when displaying different sheet.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -