简体   繁体   English

Excel等效的Google Docs函数可以“ query()”自定义VBA函数

[英]Excel equivalent Google Docs function to “query()” custom VBA function

I am transitioning from Google Docs to Excel and running int oproblems with equilivent function: specifically the Google Docs: Query() 我正在从Google Docs过渡到Excel,并运行带有均衡功能的int麻烦:特别是Google Docs:Query()

From googleing around I know that there is no Query in Excel and I have started to make a VBA function to do the same thing but running into trouble 通过谷歌搜索,我知道Excel中没有查询,并且我已经开始制作一个VBA函数来做同样的事情,但是遇到了麻烦

The original Google Docs query =QUERY('GP Referrals 2012-2013'!A15:Z ; "SELECT A, Z WHERE J = 'WH' ORDER BY Z DESC LIMIT 9", 0) 原始Google文档查询= QUERY('GP Referrals 2012-2013'!A15:Z;“ SELECT A,Z WHERE J ='WH'ORDER BY Z DESC LIMIT 9”,0)

A is a string, Z is a number and J is one of three possible strings. A是一个字符串,Z是一个数字,J是三个可能的字符串之一。 I run this three times with different values in J. 我在J中使用不同的值运行了3次。

Is there way to do this in Excel. 有没有办法在Excel中执行此操作。 I have a second sheet setup to get put the results of this in. 我有第二个工作表设置来获取结果。

I have a function started but I am a but stuck as to how to get to the next step. 我已经启动了一个功能,但是对于如何进行下一步我还是很困惑。 Any help is a appreciated. 任何帮助表示赞赏。

Function getTopGPs(clinic As String) As Integer
    Dim activeSheet As Object
    Set activeSheet = Worksheets(1)

    Dim rawRange As Object
    Set rawRange = activeSheet.Range("A15:Z65536")

    // How can I go from here?

End Function 结束功能

Based on @chuff's approach, give your data array labels (I chose A > Z from A14:Z14) and name the array (A14:Zn) - I chose GParry . 基于@chuff的方法,给您的数据数组标签(我从A14:Z14中选择A > Z )并命名该数组(A14:Zn)-我选择了GParry

DATA > Get External Data - From Other Sources, From Microsoft Query, Databases, Excel Files*, OK. 数据>获取外部数据-从其他来源,从Microsoft Query,数据库,Excel文件*,确定。 Select your workbook name, OK, Table: GParry, Add, Close. 选择您的工作簿名称,确定,表:GParry,添加,关闭。

In the list under GParry, double-click on A, J and Z in turn, then click on the SQL button. 在GParry下的列表中,依次双击A,J和Z,然后单击SQL按钮。 In SQL statement: change SELECT to SELECT TOP 9 and append: 在SQL语句中:将SELECT更改为SELECT TOP 9并追加:

WHERE J = 'WH'  
ORDER BY Z DESC 

OK, OK. 好的好的。

If you want the results back into Excel just select the extract (top left), Edit, Copy and Paste where it suits you. 如果希望将结果返回到Excel,只需选择适合的摘录(左上方),“编辑”,“复制”和“粘贴”。

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

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