Excel VBA - Populate a column on one sheet with values from another sheet based on 3 criteria (complicated IF AND related VBA with wildcards) -
i new @ excel vba , despite efforts cannot seem find similar example online use solution issue.
i creating table of data related inventory of automobiles. workbook have set has 2 tabs. first labeled "feeder", , contains table of hardcoded inputs (automobile values). second labeled "sheet1" , contains raw data inventory. sheet 1 requires automobile values in column "i". goal set workbook column labeled "values" within "sheet1", autopopulated click of button value inputs feeder sheet. tricky part (for me) values based on 1) automobile type (i.e. sedan/ pickup/ etc.), 2) color (different colors have different values), , 3) manufacture year. approaching @ first if , statement, thought creating macro more efficient route take.
i have working list, many more automobile types go (400+ total). if @ thsi stage can [hopefully] figure out rest.
your appreciated.
screen shots here: feeder table , sheet1 inventory list
my code:
sub valuefill() dim x integer x = 3 range("a" & rows.count).end(xlup).row if ucase(sheets("sheet1").range("a" & x).text) = "pickup*" , ucase(sheets("sheet1").text("c" & x).value) = "red*" range("i" & x).formula = application.worksheetfunction.index(sheets("feeder").range("c" & rows.count).end(xlup).row, application.worksheetfunction.match(sheets("sheet1").range("f" & x), sheets("feeder").range("b" & rows.count).end(xlup).row, 0), 1) elseif ucase(sheets("sheet1").range("a" & x).text) = "pickup*" , ucase(sheets("sheet1").text("c" & x).value) = "blue*" range("i" & x).formula = application.worksheetfunction.index(sheets("feeder").range("d" & rows.count).end(xlup).row, application.worksheetfunction.match(sheets("sheet1").range("f" & x), sheets("feeder").range("b" & rows.count).end(xlup).row, 0), 1) elseif ucase(sheets("sheet1").range("a" & x).text) = "sedan*" , ucase(sheets("sheet1").text("c" & x).value) = "red*" range("i" & x).formula = application.worksheetfunction.index(sheets("feeder").range("e" & rows.count).end(xlup).row, application.worksheetfunction.match(sheets("sheet1").range("f" & x), sheets("feeder").range("b" & rows.count).end(xlup).row, 0), 1) elseif ucase(sheets("sheet1").range("a" & x).text) = "sedan*" , ucase(sheets("sheet1").text("c" & x).value) = "blue*" range("i" & x).formula = application.worksheetfunction.index(sheets("feeder").range("f" & rows.count).end(xlup).row, application.worksheetfunction.match(sheets("sheet1").range("f" & x), sheets("feeder").range("b" & rows.count).end(xlup).row, 0), 1) 'i keep "elseif-ing" each combination of auto type , color, index match year... else: range("i" & x).text = "error" end if next end sub
my knee-jerk reaction use 2 different functions, since color , type interdependent: 1 handling year , 1 handling type , color of vehicle. like
sub valuefill() car = 1 last 'this loop on cars in sheet1 color = type_color(car) year = get_year(car) price = sheets("feeder").cells(year, color).value function get_year(car) 'gets year value give car , returns corresponding row number of year, i.e car year 2009 row 10 in feeder end function function type_color() 'will first type convert based on color 'gets type of car , returns left column index type 'i.e. type = pickup column index = 3 (column c) if color not same column value above offset 'i.e. blue pickup column index + 1 -> 4 end function
Comments
Post a Comment