Hai everybody,
I connect my excel 2003 to an Oracle database. Then I use a query to retreive some data from oracle and put it into an excel sheet.
In the query I generate an formula for excel (including the rownumber) Then problem is that excel won't accept this formula and display's it as text.
Entering the cell and close it (<F2> followd by <ENTER>) results in a working formula.
If I put the FORMULA field into a fariable i get a error 1004 that is not giving me a direction for the problem .
Does any one have a good solution for this problem?
Below is the code I'm using:
The FORMULA field is a string value. apparently Excel puts a ' in front of the FORMULA string and this ' is not removable by using the mid() statement.
Hoping to hear from you soon,
Harm
I connect my excel 2003 to an Oracle database. Then I use a query to retreive some data from oracle and put it into an excel sheet.
In the query I generate an formula for excel (including the rownumber) Then problem is that excel won't accept this formula and display's it as text.
Entering the cell and close it (<F2> followd by <ENTER>) results in a working formula.
If I put the FORMULA field into a fariable i get a error 1004 that is not giving me a direction for the problem .
Does any one have a good solution for this problem?
Below is the code I'm using:
Code:
Sub test()
Dim SQL As String
Dim tmp As String
Dim tmp2 As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
' open query file and load the query
Open "D:\ontwikkeling\test.sql" For Input As #1
While Not EOF(1)
Line Input #1, tmp
SQL = SQL + tmp + Chr(13) + Chr(10)
Wend
Close #1
' open the connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=xx;Uid=xx;Pwd=xx;"
cn.Open
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Source = SQL
rs.Open
R = 2
rs.MoveFirst
While Not rs.EOF
Sheets("TEST").Cells(R, 1).Value = rs.Fields("DW")
Sheets("TEST").Cells(R, 2).Value = rs.Fields("FR")
Sheets("TEST").Cells(R, 3).Value = rs.Fields("ZS")
Sheets("TEST").Cells(R, 4).Value = rs.Fields("TB")
Sheets("TEST").Cells(R, 5).Value = rs.Fields("AQ")
Sheets("TEST").Cells(R, 5).Value= rs.Fields("FORMULA")
Range("G" & R).Select
ActiveCell.FormulaR1C1 = rs.Fields("FORMULE")
Range("H" & R).Select
ActiveCell.Formula = rs.Fields("FORMULE")
tmp = rs.Fields("FORMULE")
Range("I" & R).Select
ActiveCell.FormulaR1C1 = tmp [COLOR=red] 'results in error 1004[/COLOR]
R = R + 1
rs.MoveNext
Wend
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
The FORMULA field is a string value. apparently Excel puts a ' in front of the FORMULA string and this ' is not removable by using the mid() statement.
Hoping to hear from you soon,
Harm