我一直在研究一个新工具,我需要它来根据单元格相等来运行查询。
例如,
我在 excel 中有 3 个具有数据验证的单元格。C4:部门 C5:组 C6:类别
基本上,如果(全部)被选中,则运行第一个查询,否则运行第二个。我需要 Group 根据单元格的样子运行查询:
If Sheets("Rollup").Range("C5").Value = "(All)" Then
Sheets("Codes").Range("B3:XFD1048576").Clear
cn.Open SQLServerConnString
strQuery = "Select DEPT_CATG_GRP_DESC from dbo.Rollup GROUP BY DEPT_CATG_GRP_DESC ORDER BY DEPT_CATG_GRP_DESC"
Set rs = cn.Execute(strQuery)
Sheets("Codes").Range("B3").CopyFromRecordset rs
rs.Close
cn.Close
Else Sheets("Codes").Range("B3:XFD1048576").Clear
cn.Open SQLServerConnString
strQuery = "Select DEPT_CATG_GRP_DESC WHERE DEPT_CATG_GRP_DESC = C5.Value from dbo.Rollup GROUP BY DEPT_CATG_GRP_DESC ORDER BY DEPT_CATG_GRP_DESC"
Set rs = cn.Execute(strQuery)
Sheets("Codes").Range("B3").CopyFromRecordset rs
rs.Close
cn.Close
End If