此函数打开与 sql 数据库的连接,收集数据并将其带回并将其复制到单元格 O6 及以后。我遇到了两个问题。我的第一个是我想选择要查询的单元格范围。范围从 I6 开始,然后转到单元格 I“lastrow”,最后一个单元格包含我要查询的数据。
我不知道在我的查询中说什么:
where s.cusip = ""
2. 它告诉我有一个未定义的用户定义类型。
任何帮助是极大的赞赏
Private Sub CommandButton1_Click()
Call datacollect_alternate ' my code
End Sub
Public Sub datacollect_alternate()
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim i_date As String
cmd.ActiveConnection = OpenConnectionDPDMView
cmd.CommandText = "select s.description, s.rate coupon, sa.rrb_factor from dpdm.security s left join dpdm.security_analytics sa on s.security_id = sa.security_id where s.cusip= '" & Range("i6").Value & "' And sa.as_of_date = trunc(sysdate)"
Set rs = cmd.Execute
'Declare variables'
Dim Lastrow As Integer
'Lastrow = Cells(Cells.rows.Count, "C").End(xlUp).Row
Lastrow = Range("c65336").End(xlUp).Row
'Copy Data to Excel'
ActiveSheet.Range("O6").CopyFromRecordset rs
copy_cells (Lastrow)
End Sub