vba - Insert new row and sort automatic in Excel -
i have table in excel list of names linked data. able create new rows (with data form-alike) , have them sorted existing rows.
i don't know how code vba in excel , can't find examples insert rows based on data. examples insert new blank rows style table.
i've got insert new row input value of user:
sub test_function() dim val string val = inputbox("enter name", "may know name!") 'inserting row @ at row 2 range("a3").entirerow.insert range("a3").formula = val ' end sub
more information: data in lay-out: name - money provided w1 - money providedw2 - drinks w1 - drinks w2 - total money owed
when entering new name, row needs copy formulas other rows. @ bottom of sheet row sum of 'money provided' , 'money owed'. (i think therefore can't add last row, rather insert new one, not sure tho...)
i wouldn't insert new row, rather put results of insertion @ end of sheet:
lastrow = range("a1").end(xldown).row + 1 range("a" & lastrow) = data1 range("b" & lastrow) = data2 'etc.
and sorting whole sheet key prefer (this example sorting a-c in descending order column - recorded macro):
columns("a:c").select activeworkbook.worksheets("sheet1").sort.sortfields.clear activeworkbook.worksheets("sheet1").sort.sortfields.add key:=range("a1:a" & lastrow), _ sorton:=xlsortonvalues, order:=xlascending, dataoption:=xlsortnormal activeworkbook.worksheets("sheet1").sort .setrange range("a1:c" & lastrow) .header = xlguess .matchcase = false .orientation = xltoptobottom .sortmethod = xlpinyin .apply end
Comments
Post a Comment