-1

我需要一个可以根据 excel 中的值自动创建选择雄蕊的宏/vba。示例如下。该查询可以硬编码为“SELECT * FROM PRDTBL WHERE”,其余部分应由宏处理,它将基于 A01、A02 和 A03 中的值。如果其中一个值为空白,则它将被忽略。任何人都可以给我一个关于如何实现它的想法/链接?谢谢

ID      QUERY                                                                   A01     A02     A03     Remark
1001    SELECT * FROM PRDTBL WHERE A01='ASIA' AND A02='MACHINE' AND A03='G1234' ASIA    MACHINE G1234   
1001    SELECT * FROM PRDTBL WHERE A01='EURO' AND A02='MACHINE' AND A03='F101'  EURO    MACHINE F101    
1004    SELECT * FROM PRDTBL WHERE A01='EURO' AND A03='ASS1'                    EURO    ASS1    
1003    SELECT * FROM PRDTBL WHERE A01='LATIN' AND A02='FURNITURE'              LATIN   FURNITURE       
1005    SELECT * FROM PRDTBL WHERE A01='AUS'                                    AUS         
4

1 回答 1

0

对于这样的快速操作,我只需创建一个公式并使用“&”符号将字符串连接在一起:

="SELECT * FROM PRDTBL WHERE "&IF(B1="","","A01 = '"&B1&"'")&IF(C1="","",IF(B1<>""," AND ","")&"A02 = '"&C1&"'")&IF(D1="","",IF(OR(B1<>"",C1<>"")," AND ","")& "A03 = '"&D1&"'")
于 2013-10-05T11:17:16.517 回答