1903emre34@gmail.com
Altın Üye
- Katılım
- 29 Mayıs 2016
- Mesajlar
- 946
- Excel Vers. ve Dili
- Microsoft Excel 2013 Türkçe
Merhabalar,
aşağıdaki kod ile girilen tarihler arasında döviz kurlarını ekrana gelmesini sağlıyor , yalnız resmi tatil günlerinde bile ekrana döviz kurları getiriyor kodlarda nasıl değişiklik yapabiliriz? Resmi,iş tatil gün denk gelirse -- çizgi gelsin
aşağıdaki kod ile girilen tarihler arasında döviz kurlarını ekrana gelmesini sağlıyor , yalnız resmi tatil günlerinde bile ekrana döviz kurları getiriyor kodlarda nasıl değişiklik yapabiliriz? Resmi,iş tatil gün denk gelirse -- çizgi gelsin
Kod:
Option Explicit
Sub SORGULA()
Dim SR As Worksheet, Sayfa_Adı As String, SK As Worksheet
Dim X, Y, Z, KONTROL As Byte
Dim URL1 As String, SATIR As Long, SAY As Byte
Dim EURO_BUL As Range, EURO_SATIR As Long, SÜTUN As Integer, EURO_SÜTUN As Byte
Dim USD_BUL As Range, USD_SATIR As Long, USD_SÜTUN As Byte
Dim GBP_BUL As Range, GBP_SATIR As Long, GBP_SÜTUN As Byte
Dim Versiyon As Byte
Application.ScreenUpdating = False
Versiyon = Val(Application.Version)
Set SR = Sheets("RAPOR")
SR.Select
If [B1] = "" Then MsgBox "Lütfen ilk tarihi giriniz !", vbExclamation, "Dikkat !": [B1].Select: Exit Sub
If [B2] = "" Then MsgBox "Lütfen son tarihi giriniz !", vbExclamation, "Dikkat !": [B2].Select: Exit Sub
If [B2] < [B1] Then
MsgBox "Son tarih ilk tarihten küçük olamaz !" _
& Chr(10) & Chr(10) & "Lütfen girdiğiniz bilgileri kontrol ediniz.", vbCritical, "Dikkat !"
[B2].ClearContents
[B2].Select
Exit Sub
End If
[A6:M65536].ClearContents
On Error Resume Next
Application.DisplayAlerts = False
Sheets("KURLAR").Delete
Application.DisplayAlerts = True
Sheets.Add
Sayfa_Adı = "KURLAR"
ActiveSheet.Name = Sayfa_Adı
Set SK = Sheets(Sayfa_Adı)
With Application
.DecimalSeparator = "."
.ThousandsSeparator = ","
.UseSystemSeparators = False
End With
SR.Select
BEKLEME.Show
Application.Wait (Now + TimeValue("0:00:01"))
For X = SR.[B1] - 1 To SR.[B2] - 1
If X > Date - 1 Then Exit For
KONTROL = Weekday(X, vbMonday)
If KONTROL > 5 Then
Y = X - (KONTROL - 5)
Else
Y = X
End If
On Error Resume Next
URL1 = "URL;http://www.tcmb.gov.tr/kurlar/" & Year(Y) & Format(Month(Y), "00") & "/" & Format(Day(Y), "00") & Format(Month(Y), "00") & Year(Y) & ".xml"
With SK.QueryTables.Add(Connection:=URL1, Destination:=SK.Range("A1"))
.Name = Y
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
SATIR = SR.[A65536].End(3).Row + 1
If SK.[A1] <> "" Then
Set EURO_BUL = SK.[A:A].Find(What:="EUR", LookAt:=xlPart)
If Not EURO_BUL Is Nothing Then
EURO_SATIR = EURO_BUL.Row
For SÜTUN = 2 To 256
SAY = WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Döviz Alış") + WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Forex Buying")
If IsNumeric(Right(SK.Cells(EURO_SATIR, SÜTUN), 1)) = True And SAY > 0 Then
EURO_SÜTUN = SÜTUN
Exit For
End If
Next
End If
Set USD_BUL = SK.[A:A].Find(What:="USD", LookAt:=xlPart)
If Not USD_BUL Is Nothing Then
USD_SATIR = USD_BUL.Row
For SÜTUN = 2 To 256
SAY = WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Döviz Alış") + WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Forex Buying")
If IsNumeric(Right(SK.Cells(USD_SATIR, SÜTUN), 1)) = True And SAY > 0 Then
USD_SÜTUN = SÜTUN
Exit For
End If
Next
End If
Set GBP_BUL = SK.[A:A].Find(What:="GBP", LookAt:=xlPart)
If Not GBP_BUL Is Nothing Then
GBP_SATIR = GBP_BUL.Row
For SÜTUN = 2 To 256
SAY = WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Döviz Alış") + WorksheetFunction.CountIf(SK.Range(SK.Cells(1, SÜTUN), SK.Cells(65536, SÜTUN)), "Forex Buying")
If IsNumeric(Right(SK.Cells(GBP_SATIR, SÜTUN), 1)) = True And SAY > 0 Then
GBP_SÜTUN = SÜTUN
Exit For
End If
Next
End If
SR.Cells(SATIR, 1) = X + 1
SR.Cells(SATIR, 2) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 3) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 1), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 1), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 4) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 2), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 2), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 5) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 3), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 3), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 6) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 7) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 1), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 1), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 8) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 2), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 2), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 9) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 3), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 3), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 10) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 11) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 1), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 1), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 12) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 2), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 2), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 13) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 3), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 3), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
End If
For Z = X To X - 7 Step -1
If SK.[A1] <> "" Then GoTo Devam
KONTROL = Weekday(Z, vbMonday)
If KONTROL > 5 Then
Y = Z - (KONTROL - 5)
Else
Y = Z
End If
On Error Resume Next
URL1 = "URL;http://www.tcmb.gov.tr/kurlar/" & Year(Y) & Format(Month(Y), "00") & "/" & Format(Day(Y), "00") & Format(Month(Y), "00") & Year(Y) & ".xml"
With SK.QueryTables.Add(Connection:=URL1, Destination:=SK.Range("A1"))
.Name = Y
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
SATIR = SR.[A65536].End(3).Row + 1
If SK.[A1] <> "" Then
SR.Cells(SATIR, 1) = X + 1
SR.Cells(SATIR, 2) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 3) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 1), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 1), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 4) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 2), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 2), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 5) = IIf(Left(SK.Cells(EURO_SATIR, EURO_SÜTUN + 3), 1) = 0, Replace(SK.Cells(EURO_SATIR, EURO_SÜTUN + 3), ".", ",") * 1, SK.Cells(EURO_SATIR, EURO_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 6) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 7) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 1), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 1), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 8) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 2), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 2), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 9) = IIf(Left(SK.Cells(USD_SATIR, USD_SÜTUN + 3), 1) = 0, Replace(SK.Cells(USD_SATIR, USD_SÜTUN + 3), ".", ",") * 1, SK.Cells(USD_SATIR, USD_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 10) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 11) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 1), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 1), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 1) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 12) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 2), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 2), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 2) / IIf(Versiyon < 12, 10000, 1))
SR.Cells(SATIR, 13) = IIf(Left(SK.Cells(GBP_SATIR, GBP_SÜTUN + 3), 1) = 0, Replace(SK.Cells(GBP_SATIR, GBP_SÜTUN + 3), ".", ",") * 1, SK.Cells(GBP_SATIR, GBP_SÜTUN + 3) / IIf(Versiyon < 12, 10000, 1))
End If
DoEvents
Next
Devam:
Next
Application.DisplayAlerts = False
SK.Delete
Application.DisplayAlerts = True
With Application
.DecimalSeparator = ","
.ThousandsSeparator = "."
.UseSystemSeparators = False
End With
[A1].Select
Application.ScreenUpdating = True
Unload BEKLEME
[K1].Activate
MsgBox "Döviz sorgulama işlemi başarıyla tamamlanmıştır.", vbInformation
End Sub
Sub TCMB()
On Error GoTo Hata
Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & "http://www.tcmb.gov.tr", vbMaximizedFocus
Exit Sub
Hata:
MsgBox "İnternet bağlantısı şu anda kurulamıyor." _
& Chr(10) & "Lütfen daha sonra tekrar deneyiniz.", vbCritical, "Dikkat !"
End Sub
