I want to transpose rows into columns in ms-access

前端 未结 3 459
太阳男子
太阳男子 2021-01-26 00:57

I need to transpose rows into columns in MS Access database, VBA, SQL both the codes are welcome.

Table

    | Name | Ticker | ID | Innovation | Quality |         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 01:42

    Access TRANSFORM is not really intuitive and easy to use and I do not think you can use it that way. Each result row is supposed to be an aggregate of your table. I know of no way to get the previous field names into a new column.

    See a working example: TRANSFORM and PIVOT in Access 2013 SQL

    What you really seem to want is just a new presentation to the existing data.

    Excel might help.

    I have never exported pdf from Access but from Excel is easy. Here is an example:

    Sub ExportPdf(path As String, Optional openAfter As Boolean)
    
    ''calculate best range for print area
    Dim lastCol As Integer
    Dim firstRow As Integer
    Dim lastRow As Integer
    
    lastCol = pt.TableRange2.Columns(pt.TableRange2.Columns.Count).Column
    firstRow = pt.TableRange2.Rows(1).Row
    lastRow = ms.Cells(pt.TableRange2.Rows.Count * 3, 1).End(xlUp).Row
    
    Worksheets(ContextSheet).PageSetup.PrintArea = Range(Cells(firstRow, 1), Cells(lastRow, lastCol)).Address
    
    Worksheets(ContextSheet).ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        path & "\Area " & getPivotTablePageFilters(getPivotTable()) & ".pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=openAfter
    End Sub
    

提交回复
热议问题