简体   繁体   English

使用vba在excel列上执行sql查询

[英]execute sql query on excel columns using vba

I'm doing excel data verification and would like to view any discrepancies within each column. 我正在进行excel数据验证,并希望查看每列中的任何差异。 And I think executing 我认为执行

"select distinct column1 from table_name"

is efficient. 是有效的。 Is there a way to do that in vba with/without connecting to any database? 在vba中,有/没有连接任何数据库的方法吗? Any advice would be appreciated. 任何意见,将不胜感激。

This code should do the SELECT DISTINCT for one column: 此代码应对一列执行SELECT DISTINCT:

ActiveSheet.Range("A2:A65536").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ActiveSheet.Range("B2"), Unique:=True

The code will paste the Distinct values from activesheet column A to column B. Hope this helps 该代码会将Distinct值从Activesheet列A粘贴到B列。希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM