Mid Komutu Hakkında yardım

Katılım
13 Şubat 2009
Mesajlar
289
Excel Vers. ve Dili
office 2003
Merhaba ;

Aşağıdaki kodda listbox'a gelecek olan verilerin sadece "CH" ile başlayanların gelmesi gerekiyor.

Yani 'If Mid(sayfa.Cells(i, 4).Value, 1, 2) = "CH" Then buna benzer bir kod ile
kısıtlama yapmam gerekiyor ama beceremedim.




Private Sub UserForm_Initialize()
On Local Error Resume Next
Dim bugun As Long, tarih As Long, kod As String, kontrol As Boolean
Dim con As Object, rs As Object, sorgu As String

With Sayfa2
bugun = CLng(CDate(Date)) - 5
tarih = CLng(bugun)

Set con = CreateObject("adodb.connection")
con.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.FullName & _
";extended properties=""excel 8.0;hdr=yes"""
sorgu = "select * from [Sayfa2$] where clng(cdate(VADE_TARIHI)) <=" & tarih
Set rs = CreateObject("adodb.recordset")
rs.Open sorgu, con, 1, 1
Do While Not rs.EOF
kod = CStr(rs("CARI_HESAP_KOD").Value)
kontrol = Sayfa8.Range("a:a").Find(kod, , xlValues, , , xlNext, False)

If kontrol = False Then
With ListBox4
.ColumnCount = 4
.AddItem rs("ad")
.List(.ListCount - 1, 1) = rs("CARI_HESAP_ADI")
.List(.ListCount - 1, 2) = rs("CARI_HESAP_KOD")
.List(.ListCount - 1, 3) = FormatDateTime(rs("VADE_TARIHI").Value, vbShortDate)
End With
End If
kontrol = False
rs.MoveNext
Loop
End With
MsgBox ""
i = Empty: a = Empty: bugun = Empty
tarih = Empty
kod = vbNullString
sorgu = vbNullString
Set con = Nothing
Set rs = Nothing
End Sub
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,248
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
:cool:
Kod:
If Left(Sheets("sayfa").Cells(i, 4).Value, 2) = "CH" Then
 

Orion1

Uzman
Uzman
Katılım
1 Mart 2005
Mesajlar
22,248
Excel Vers. ve Dili
Win7 Home Basic TR 64 Bit

Ofis-2010-TR 32 Bit
Bu komutu daha önce denedim hata veriyor.

If Left(Sheets("sayfa").Cells(i, 4).Value, 2) = "CH" Then

Ent With Without with hatası veriyor.
Bu komutta hata yok siz başka bir yerde hata yapıyorsunuz.End with veya end if veya next kullanmanız gereken bir sonlandırmayı kullanmıyorsunuz ondan hata veriyor
 
Üst