Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String Set cn = New ADODB.Connection cn.ConnectionString = 'Get one from http://www.connectionstrings.com/oracle 'eg. "Driver={Oracle in OraHome92};Dbq=tns;Uid=uid;Pwd=pwd;" cn.Open sql = Your SQL Set rs = cn.Execute(sql) for loop or something to paste records rs.Close cn.Close Set rs = Nothing Set cn = Nothing </code></pre> <p>if you format your spreadsheet properly you could assign rs to a Variant and then assign the variant to a range instead of looping through it.</p> <p><strong>Edit</strong></p> <p>With your current SQL you would need to loop through each cell and query the db, then save the results to A3:A5. <strong>Edit 2</strong>, Something like that:</p> <pre><code>Private Function GetRow(user As String) As Variant Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String Dim v As Variant Set cn = New ADODB.Connection cn.ConnectionString = "Driver={Oracle in OraHome92};Dbq=tns;Uid=uid;Pwd=pwd;" cn.Open sql = "SELECT i.id, i.forename, i.surname FROM individual i WHERE UPPER(REPLACE('" &amp; user &amp; "', ' ', '')) = UPPER(REPLACE(i.surname|| i.forename, ' ', '')) AND NVL(i.ind_efface, 'N') = 'N'" Set rs = cn.Execute(sql) v = rs.GetRows() GetRow = v rs.Close cn.Close Set rs = Nothing Set cn = Nothing End Function Sub a() Dim user As String For i = 2 To x user = ActiveSheet.Cells(i, 1).Value GetRow (user) ActiveSheet.Cells(i, 2).Value = GetRow(0) ActiveSheet.Cells(i, 3).Value = GetRow(1) ActiveSheet.Cells(i, 4).Value = GetRow(2) Next End Sub </code></pre> <p>Note that I have used different cells that you wanted and the GetRow is 2D not 1D, but is hard for me to write it up with no access to actual spreadsheet/db</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload