excel - Passing InputBox entry generates Run-time error '424': Object required -
an input box comes come in item name, illustration "test item". input box comes come in cost, illustration "13.2". code designed find first empty cell in column b , come in item , offset 1 column right , come in cost.
i getting run-time error '424': object required on
activecell.offset(1, 0).select.formular1c1 = item
sub addswitem() dim item string dim cost string item = inputbox("item") cost = inputbox("cost") range("b11").select selection.end(xldown).select activecell.offset(1, 0).select activecell.formular1c1 = item activecell.offset(0, 2).select activecell.formular1c1 = cost end sub
i guess figured out wanted here notes on alternative coding.
using vba can address cells straight , not utilize active cells. active cells useful when want user define results placed. if locations known can utilize range object.
below several examples. include standard vba error logic , debug techniques.
sub addswitem() on error goto local_err dim item string dim cost string dim rng range item = inputbox("item") cost = inputbox("cost") ' qa code here set rng = range("b11") rng(1, 0) = item rng(0, 2) = cost ' or utilize direct entry rng(2, 0) = inputbox("item 2") rng(1, 2) = inputbox("cost 2") ' or range("b11")(3, 0) = inputbox("item 3") range("b11")(2, 2) = inputbox("cost 3") local_exit: exit sub local_err: msgbox err & " " & err.description resume local_err ' ctrl-break debug @ point resume ' right click -set next statement here resume on failed line end sub excel excel-vba
No comments:
Post a Comment