Başka Dosyadaki Dolu Satır Sayısını Hesaplamak

Katılım
26 Ocak 2007
Mesajlar
4,625
Excel Vers. ve Dili
Ofis 2016
Merhaba Arkadaşlar,
Kapalı durumda olan bir dosyamız var : SATIŞLAR
SATIŞLAR dosyasnın F sütununda F5:F10000 aralığında kaç adet hücrenin dolu olduğunu o dosyayı açmadan hesaplamak mümkün müdür ?
 
Merhaba,

Deneyiniz. d değişkenindeki dosya yolunu ve Sayfa1 olarak yazdığım sayfa adını kendinize göre uyarlarsınız.
Kod:
Sub say()
    Dim d As String
    d = "'C:\Users\Desktop\[SATIŞLAR.xlsx]"
    MsgBox Application.ExecuteExcel4Macro("COUNTA(" & d & "Sayfa1'!R5C6:R10000C6)")
End Sub
 
Merhaba,

Deneyiniz. d değişkenindeki dosya yolunu ve Sayfa1 olarak yazdığım sayfa adını kendinize göre uyarlarsınız.
Kod:
Sub say()
    Dim d As String
    d = "'C:\Users\Desktop\[SATIŞLAR.xlsx]"
    MsgBox Application.ExecuteExcel4Macro("COUNTA(" & d & "Sayfa1'!R5C6:R10000C6)")
End Sub
Ömer üstadın çok çok teşekkür ediyorum. Harika bir kod oldu. Sağlıcakla kalın
 
ADO ile alternatif;

C++:
Option Explicit

Sub Dolu_Satir_Say()
    Dim Baglanti As Object, Kayit_Seti As Object, Yol As String, Say As Long
    
    Set Baglanti = CreateObject("AdoDb.Connection")
    Set Kayit_Seti = CreateObject("AdoDb.Recordset")

    Yol = ThisWorkbook.Path & "\SATIŞLAR.xlsx"
    
    Baglanti.Open "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" & _
    Yol & ";Extended Properties=""Excel 12.0;Hdr=No;Imex=1"""
    
    On Error Resume Next
    Kayit_Seti.Open "Select F1 From [Sayfa1$F5:F10000] Where Not IsNull(F1)", Baglanti, 1, 1
    Say = Kayit_Seti.RecordCount
    On Error GoTo 0
    
    MsgBox "Dolu satır sayısı ; " & Say
    
    If Kayit_Seti.State <> 0 Then Kayit_Seti.Close
    If Baglanti.State <> 0 Then Baglanti.Close

    Set Kayit_Seti = Nothing
    Set Baglanti = Nothing
End Sub
 
ADO ile alternatif;

C++:
Option Explicit

Sub Dolu_Satir_Say()
    Dim Baglanti As Object, Kayit_Seti As Object, Yol As String, Say As Long
   
    Set Baglanti = CreateObject("AdoDb.Connection")
    Set Kayit_Seti = CreateObject("AdoDb.Recordset")

    Yol = ThisWorkbook.Path & "\SATIŞLAR.xlsx"
   
    Baglanti.Open "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" & _
    Yol & ";Extended Properties=""Excel 12.0;Hdr=No;Imex=1"""
   
    On Error Resume Next
    Kayit_Seti.Open "Select F1 From [Sayfa1$F5:F10000] Where Not IsNull(F1)", Baglanti, 1, 1
    Say = Kayit_Seti.RecordCount
    On Error GoTo 0
   
    MsgBox "Dolu satır sayısı ; " & Say
   
    If Kayit_Seti.State <> 0 Then Kayit_Seti.Close
    If Baglanti.State <> 0 Then Baglanti.Close

    Set Kayit_Seti = Nothing
    Set Baglanti = Nothing
End Sub
Çok teşekkür ediyorum Korhan Ayhan üstadım. Sağlıcakla kalın
 
Üstad ThisWorkbook.Path modeli uygulanabilir mi ?
d = "'C:\Users\Desktop\[SATIŞLAR.xlsx]" yerine
d = ThisWorkbook.Path & "\[SATIŞLAR.xlsx]"

Deneyiniz.
Kod:
Sub say()
    Dim d As String
    d = ThisWorkbook.Path & "\[SATIŞLAR.xlsx]"
    MsgBox Application.ExecuteExcel4Macro("COUNTA('" & d & "Sayfa1'!R5C6:R10000C6)")
End Sub
 
Deneyiniz.
Kod:
Sub say()
    Dim d As String
    d = ThisWorkbook.Path & "\[SATIŞLAR.xlsx]"
    MsgBox Application.ExecuteExcel4Macro("COUNTA('" & d & "Sayfa1'!R5C6:R10000C6)")
End Sub
Üstad bu şekilde de çok iyi bir alternatif kod oldu. Çok çok sağolun, var olun, sağlıcakla kalın
 
Geri
Üst