我正在使用Access中有50列和800行的表。我想获取每行中每个非空字段的列名,保持第一列的值保持不变,例如
感谢您帮助我查询。
祝你好运
答案 0 :(得分:0)
在Access中查询表单:
SELECT
customer_name,
IIF(product_1 IS NOT NULL, "Product_1", NULL),
IIF(product_2 IS NOT NULL, "Product_2", NULL),
IIF(product_3 IS NOT NULL, "Product_3", NULL),
IIF(product_4 IS NOT NULL, "Product_4", NULL),
IIF(product_5 IS NOT NULL, "Product_5", NULL),
IIF(product_6 IS NOT NULL, "Product_6", NULL),
IIF(product_7 IS NOT NULL, "Product_7", NULL),
IIF(product_8 IS NOT NULL, "Product_8", NULL),
IIF(product_9 IS NOT NULL, "Product_9", NULL),
IIF(product_10 IS NOT NULL, "Product_10", NULL),
IIF(product_11 IS NOT NULL, "Product_11", NULL),
IIF(product_12 IS NOT NULL, "Product_12", NULL),
IIF(product_13 IS NOT NULL, "Product_13", NULL),
IIF(product_14 IS NOT NULL, "Product_14", NULL),
IIF(product_15 IS NOT NULL, "Product_15", NULL),
IIF(product_16 IS NOT NULL, "Product_16", NULL),
IIF(product_17 IS NOT NULL, "Product_17", NULL),
IIF(product_18 IS NOT NULL, "Product_18", NULL),
IIF(product_19 IS NOT NULL, "Product_19", NULL),
IIF(product_20 IS NOT NULL, "Product_20", NULL),
IIF(product_21 IS NOT NULL, "Product_21", NULL),
IIF(product_22 IS NOT NULL, "Product_22", NULL),
IIF(product_23 IS NOT NULL, "Product_23", NULL),
IIF(product_24 IS NOT NULL, "Product_24", NULL),
IIF(product_25 IS NOT NULL, "Product_25", NULL),
IIF(product_26 IS NOT NULL, "Product_26", NULL),
IIF(product_27 IS NOT NULL, "Product_27", NULL),
IIF(product_28 IS NOT NULL, "Product_28", NULL),
IIF(product_29 IS NOT NULL, "Product_29", NULL),
IIF(product_30 IS NOT NULL, "Product_30", NULL),
IIF(product_31 IS NOT NULL, "Product_31", NULL),
IIF(product_32 IS NOT NULL, "Product_32", NULL),
IIF(product_33 IS NOT NULL, "Product_33", NULL),
IIF(product_34 IS NOT NULL, "Product_34", NULL),
IIF(product_35 IS NOT NULL, "Product_35", NULL),
IIF(product_36 IS NOT NULL, "Product_36", NULL),
IIF(product_37 IS NOT NULL, "Product_37", NULL),
IIF(product_38 IS NOT NULL, "Product_38", NULL),
IIF(product_39 IS NOT NULL, "Product_39", NULL),
IIF(product_40 IS NOT NULL, "Product_40", NULL),
IIF(product_41 IS NOT NULL, "Product_41", NULL),
IIF(product_42 IS NOT NULL, "Product_42", NULL),
IIF(product_43 IS NOT NULL, "Product_43", NULL),
IIF(product_44 IS NOT NULL, "Product_44", NULL),
IIF(product_45 IS NOT NULL, "Product_45", NULL),
IIF(product_46 IS NOT NULL, "Product_46", NULL),
IIF(product_47 IS NOT NULL, "Product_47", NULL),
IIF(product_48 IS NOT NULL, "Product_48", NULL),
IIF(product_49 IS NOT NULL, "Product_49", NULL)
FROM your_table;
答案 1 :(得分:0)
这是Excel vba:
Sub prodname()
Dim ws As Worksheet
Dim tws As Worksheet
Dim oArr() As Variant
Dim tArr() As Variant
Dim rw As Long
Dim clm As Long
Set ws = Sheets("Sheet1") 'Change to the sheet with the data
Set tws = Sheets("Sheet2") 'change to the desired output sheet
rw = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
clm = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
oArr = ws.Range(ws.Cells(1, 1), ws.Cells(rw, clm)).Value
ReDim tArr(1 To rw - 1, 1 To clm) As Variant
For i = 2 To rw
k = 2
tArr(i - 1, 1) = oArr(i, 1)
For j = 2 To clm
If oArr(i, j) <> "" Then
tArr(i - 1, k) = oArr(1, j)
k = k + 1
End If
Next j
Next i
tws.Range("A1").Resize(UBound(tArr, 1), UBound(tArr, 2)).Value = tArr
End Sub