- Katılım
- 15 Mart 2005
- Mesajlar
- 42,269
- Excel Vers. ve Dili
- Microsoft 365 Tr-En 64 Bit
Deneyiniz.
C++:
Option Explicit
Sub Lokasyonlari_Ayir()
Dim S1 As Worksheet, Dizi As Object, Say As Long
Dim Veri As Variant, Son As Long, X As Long, Zaman As Double
Dim Baglanti As Object, Kayit_Seti As Object, Sorgu As String
Dim Fis_No As Variant, Kontrol As Boolean, Kriter As Variant
Zaman = Timer
Set S1 = Sheets("Sayfa2")
Set Dizi = VBA.CreateObject("Scripting.Dictionary")
Set Baglanti = VBA.CreateObject("AdoDb.Connection")
Set Kayit_Seti = VBA.CreateObject("AdoDb.Recordset")
With S1.Range("J2:AA" & S1.Rows.Count)
.Clear
End With
Son = S1.Cells(S1.Rows.Count, 1).End(3).Row
Veri = S1.Range("A2:H" & Son).Value
For X = LBound(Veri, 1) To UBound(Veri, 1)
If Veri(X, 5) <> "" Then
If Not Dizi.Exists(Veri(X, 5)) Then
Dizi.Add Veri(X, 5), Array(1, X)
Else
Kriter = Dizi.Item(Veri(X, 5))
Kriter(0) = Kriter(0) + 1
Dizi.Item(Veri(X, 5)) = Kriter
End If
End If
Next
ReDim Liste(1 To UBound(Veri, 1), 1 To 1)
Baglanti.Open "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" & _
ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;Hdr=No"""
For Each Fis_No In Dizi.Keys
Sorgu = "Select * From [Sayfa2$] Where F5 = '" & Fis_No & "' And (F1 Like '391%' Or F1 Like '120.02%')"
Kayit_Seti.Open Sorgu, Baglanti, 1, 1
If Kayit_Seti.RecordCount > 0 Then Kontrol = True
Kayit_Seti.Close
Sorgu = "Select * From [Sayfa2$] Where F5 = '" & Fis_No & "' And (F1 Like '191%' Or F1 Like '320.02%')"
Kayit_Seti.Open Sorgu, Baglanti, 1, 1
If Kayit_Seti.RecordCount > 0 Then Kontrol = True
Kayit_Seti.Close
If Kontrol = True Then
For X = Dizi.Item(Fis_No)(1) To Dizi.Item(Fis_No)(1) + Dizi.Item(Fis_No)(0) - 1
Say = Say + 1
Liste(Say, 1) = "Ramada"
Next
End If
Next
If Baglanti.State <> 0 Then Baglanti.Close
If Say > 0 Then
S1.Range("J2").Resize(Say) = Liste
MsgBox "Lokasyon ayrımı yapılmıştır." & vbCrLf & vbCrLf & _
"İşlem süresi ; " & Format(Timer - Zaman, "0.00") & " Saniye", vbInformation
Else
MsgBox "Uygun kayıt bulunamadı!", vbExclamation
End If
Set S1 = Nothing
Set Dizi = Nothing
Set Baglanti = Nothing
Set Kayit_Seti = Nothing
End Sub