vba - How to add data into particular row in excel -
i want inquire how add together info into particular row in excel spreadsheet using userform
.
when add together new product sheet, want new info located under lastly row of product a, , same other products b , c.
is there way sort info when come in new info existing table?
the code have below adds info row row, no matter product enter, making table unsorted , appearing scattered.
private sub commandbutton1_click() dim lastrow object set lastrow = sheet1.range("a65536").end(xlup) lastrow.offset(1, 0).value = textbox1.text lastrow.offset(1, 1).value = textbox2.text lastrow.offset(1, 2).value = textbox3.text msgbox "one record written sheet1" if msgbox("do want go on entering data?", vbyesno + vbcritical, "caution") = vbyes textbox1.text = "" textbox2.text = "" textbox3.text = "" else end textbox1.setfocus unload me end if end sub
you can add together info lastly row , sort data.
1) lastly row see link
2) sort info can utilize simple code. below sample code sort col has headers
with sheets("sheet1") .columns("a:a").sort key1:=.range("a1"), order1:=xlascending, header:=xlyes, _ ordercustom:=1, matchcase:=false, orientation:=xltoptobottom, _ dataoption1:=xlsortnormal end
3) 1 tip using end
: see point 6 in this thread.
4) if combine both codes code this
option explicit private sub commandbutton1_click() dim lastrow long '~~> alter releavnt sheet name sheets("sheet1") lastrow = .range("a" & .rows.count).end(xlup).row + 1 .range("a" & lastrow) = textbox1.text .range("b" & lastrow) = textbox2.text .range("c" & lastrow) = textbox3.text '~~> sort data. assuming row 1 has headers .columns("a:c").sort key1:=.range("a2"), order1:=xlascending, header:=xlyes, _ ordercustom:=1, matchcase:=false, orientation:=xltoptobottom, _ dataoption1:=xlsortnormal end if msgbox("one record written sheet1. want go on entering data?", vbyesno + vbcritical, "caution") = vbyes textbox1.text = "" textbox2.text = "" textbox3.text = "" textbox1.setfocus else unload me end if end sub
excel vba excel-vba
No comments:
Post a Comment