sql - Text values in a pivot table? -
i have table (in mysql) 3 columns:
location category supplier computers company x printers company y b computers company x b printers company y b software company y c computers company y c software company z
now need make matrix containing above information, :
computers printers software company x company y b company x company y company y c company y company z
eventually need have in excel.
in reality have variable number of categories, doing in mysql join each column not option. write function in php, wondering if there's more elegant solution.
i looked pivot tables in excel, seem more suited numbers values. maybe i'm overlooking something, since never work excel myself.
any idea's?
i ran same problem pivot tables... perfect summaries, not text matrices.
i have "lifted" code examples used. here have data in columns a-d , build matrix (in same sheet) around column f.
check see if helps.
i still have trouble getting code right , please aware lot of code starts before code window.
code example 1:
'fill in values sheets("tempfile").select listrow = 1 mismatchcounter = 0 until cells(listrow, 1).value = "" ' table entry third column of list. tableentry = cells(listrow, 3).value on error resume next if err.number > 0 msgbox err.number ' position of product name within range of row titles. if tableentry <> "" tablerow = application.match(cells(listrow, 1), range("f3:" & mylastrowaddress), 0) ' 2 rows less reality ' position of product size within range of column titles. tablecolumn = application.match(cells(listrow, 2), range("g2:" & mylastcoladdress), 0) set celltofill = range("f2").offset(tablerow, tablecolumn) ' if there's entry in cell, separate new entry comma , space. if err.number = 0 if celltofill.value <> "" celltofill.value = celltofill.value & "," celltofill.value = celltofill.value & tableentry else celltofill.value = tableentry end if else mismatchcounter = mismatchcounter + 1 sheets("errors").cells(mismatchcounter, 1).value = listrow sheets("errors").cells(mismatchcounter, 2).value = cells(listrow, 1) sheets("errors").cells(mismatchcounter, 3).value = cells(listrow, 2) sheets("errors").cells(mismatchcounter, 4).value = cells(listrow, 3) sheets("errors").cells(mismatchcounter, 5).value = cells(listrow, 4) end if end if on error goto 0 listrow = listrow + 1 loop
code example 2:
sub createmanualmatrix() dim tablerow, tablecolumn integer dim tableentry string dim celltofill range 'sheet called lijst 'column names top row 'column b names left column 'column c value matrix 'matrix top row starts @ h1 'matrix left column starts @ g2 matrixlastcoladdress = range("h1").end(xltoright).address matrixlastrow = range("g65536").end(xlup).row lijstreadcolumn = 3 lijstcurrentrow = 2 'make 1 if no header used until sheets("lijst").cells(lijstcurrentrow, 1).value = "" ' table entry third column of list. tableentry = sheets("lijst").cells(lijstcurrentrow, lijstreadcolumn).value ' position of employee name within matrix. tablecolumn = application.match(sheets("lijst").cells(lijstcurrentrow, 1), range("h1:" & matrixlastcoladdress), 0) ' position of qualification name within matrix titles. tablerow = application.match(sheets("lijst").cells(lijstcurrentrow, 2), range("g2:g" & matrixlastrow), 0) set celltofill = range("g1").offset(tablerow, tablecolumn) ' if there's entry in cell, separate new entry comma , space. if celltofill.value <> "" celltofill.value = celltofill.value & "," ' add new entry cell. celltofill.value = celltofill.value & tableentry lijstcurrentrow = lijstcurrentrow + 1 loop end sub
Comments
Post a Comment