Inserting a column in the end in excel vba -
my dataset looks
category dummy1 dummy2
aan
abd
bad
boy
abcd
i want insert column names "result" in end, conditions if category starts result="pass" if category starts b result="fail"
ie, final output should this
how can in excel-vba. please me.
i editing existing spreadsheets.
dim rngtemp range set rngtemp = cells.find("*", searchorder:=xlbyrows, searchdirection:=xlprevious) each cel in range(cells(1, 1), rngtemp) if cel.value = "i live in" cel.value = "current_domicile" elseif cel.value = "i interested in purchasing" cel.value = "type_of_property" elseif cel.value = "i interested in purchasing" cel.value = "wait_time" elseif cel.value = "the reason not buying house right away because am:" cel.value = "reason_for_wait" end if next cel
i want add new column conditions above.
i not sure "files" mentioned workbooks or worksheets? anyway,i try following code , worked fine. hope in solving problem.
option explicit dim myworkbook workbook dim myworksheet worksheet sub addlastcolumn() set myworkbook = workbooks(activeworkbook.name) set myworksheet = myworkbook.sheets("worksheetname") dim myworksheetlastrow long dim myworksheetlastcolumn long dim myrowpointer long myworksheetlastcolumn = myworksheet.cells(1, columns.count).end(xltoleft).column myworksheet.cells(1, myworksheetlastcolumn + 1).value = "result" myworksheetlastrow = myworksheet.cells(rows.count, "a").end(xlup).row myrowpointer = 2 myworksheetlastrow if instr(1, myworksheet.cells(myrowpointer, 1), "a") = 1 myworksheet.cells(myrowpointer, myworksheetlastcolumn + 1).value = "pass" else myworksheet.cells(myrowpointer, myworksheetlastcolumn + 1).value = "fail" end if next end sub
Comments
Post a Comment