ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Comparing sql record to cell value (https://www.excelbanter.com/excel-programming/331118-comparing-sql-record-cell-value.html)

mozart

Comparing sql record to cell value
 

I am assigning a value to a variable from an oracle query using 0040
and a dynaset.

Eg For i = 1 To OraDynaSet.RecordCount
dbValue = OraDynaSet.Fields(0).Value
............................ bla bla


I am then trying to compare this variable with some value in a range
and am getting in all sorts of a mess with Exit For, End If :)

What I am trying to do is getting first record and compare to every
value in my range eg Range("A1:A3"). If it find a value then good and
we move onto next record. If it does not find a matching value then up
pops a msgbox and procedure stops. If all records from query are
matched in the range then naturally it also stops or does something
else without any problems


Thanks


--
mozart
------------------------------------------------------------------------
mozart's Profile: http://www.excelforum.com/member.php...o&userid=13314
View this thread: http://www.excelforum.com/showthread...hreadid=377019


mangesh_yadav[_269_]

Comparing sql record to cell value
 

if not (WorksheetFunction.Match(dbValue,range("A1:A3"),0) 0) then
msgbox "your message here"
exit sub
end if


Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=37701


mangesh_yadav[_268_]

Comparing sql record to cell value
 

Sorry, when not found, the match gives an error. You may use somethin
like this instead:

Sub Test()

On Error GoTo Err_handler
a = WorksheetFunction.Match(2, Range("A1:A3"), 0)

' your code here

Err_handler:
Exit Sub

End Sub



Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=37701


mangesh_yadav[_270_]

Comparing sql record to cell value
 

A better approach:

Sub test()

Set a = Range("a1:a3").Find(dbValue, LookIn:=xlValues)

If a Is Nothing Then
MsgBox "not found"
Exit Sub
End If

End Sub


Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=37701



All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com