RoVo1211
Gebruiker
- Lid geworden
- 24 feb 2024
- Berichten
- 61
- Besturingssysteem
- Windows 11
- Office versie
- Office 365
Ik heb een macro gemaakt die de slotkoersen van de geselecteerde fondsen naar een jaaroverzicht kopieert, maar deze geeft een foutmelding bij de opdracht
De volledige macro luidt als volgt:
Zie ook mijn commentaar in de Code
Het lijkt wel of "Set Sluiting" en/of "Set VorigeDag" de fout genereert, maar waarom is mij een raadsel.
regels 40-43, deze geven de foutmelding niet!!!
Hier lijkt de fout te zitten (regels 44-45), maar ik zie niet wat hier fout gaat.
Kan iemand mij uit de droom helpen?
Code:
With Sluiting.Offset(0, intRijAEX) 'hier krijg ik de foutmelding {regel 64)
.PasteSpecial Paste:=xlPasteValues
.Interior.Color = vbYellow
End With
De volledige macro luidt als volgt:
Code:
Dim Sluiting As Range, VorigeDag As Range, AEX As Range, Fonds1 As Range, Fonds2 As Range, Fonds3 As Range
Dim dtVandaag As Date, dtVorigeDag As Date
Dim intRijAEX As Integer, intRij1 As Integer, intRij2 As Integer, intRij3 As Integer
Dim strAEX As String, strFonds1 As String, strFonds2 As String, strFonds3 As String
Dim blnWeekend As Boolean, intKolom As Integer
Sub Slotkoersen()
Sheets(4).[A:AA].ColumnWidth = 9
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7 Then blnWeekend = True
strAEX = Left(Sheets(1).[B3].Value, 4)
strFonds1 = Left(Sheets(1).[B5].Value, 4)
strFonds2 = Left(Sheets(1).[B7].Value, 4)
strFonds3 = Left(Sheets(1).[B9].Value, 4)
intRijAEX = WorksheetFunction.Match(strAEX, Sheets(2).Range("M2:M27"), True)
intRij1 = WorksheetFunction.Match(strFonds1, Sheets(2).Range("M2:M27"), True)
intRij2 = WorksheetFunction.Match(strFonds2, Sheets(2).Range("M2:M27"), True)
intRij3 = WorksheetFunction.Match(strFonds3, Sheets(2).Range("M2:M27"), True)
dtVandaag = FormatDateTime(Date, vbShortDate)
If Weekday(Date, vbMonday) = 7 Then
dtVorigeDag = FormatDateTime(Date - 3, vbShortDate)
ElseIf Weekday(Date, vbMonday) = 6 Then
dtVorigeDag = FormatDateTime(Date - 2, vbShortDate)
Else
dtVorigeDag = FormatDateTime(Date - 1, vbShortDate)
End If
Debug.Print vbNewLine & Time & vbNewLine & _
"intRij AEX/1/2/3: " & vbNewLine & _
strAEX, intRijAEX & vbNewLine & _
Left(strFonds1, 4), intRij1 & vbNewLine & _
Left(strFonds2, 4), intRij2 & vbNewLine & _
Left(strFonds3, 4), intRij3 & vbNewLine & _
"dtVandaag: " & dtVandaag, "dtVorigeDag: " & dtVorigeDag
Set AEX = Sheets(4).[B2:AA2].Find(What:=strAEX, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds1 = Sheets(4).[B2:AA2].Find(What:=strFonds1, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds2 = Sheets(4).[B2:AA2].Find(What:=strFonds2, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds3 = Sheets(4).[B2:AA2].Find(What:=strFonds3, LookIn:=xlValues, lookat:=xlWhole)
Set Sluiting = Sheets(4).[A3:A368].Find(What:=dtVandaag, LookIn:=xlValues, lookat:=xlWhole)
Set VorigeDag = Sheets(4).[A3:A368].Find(What:=dtVorigeDag, LookIn:=xlValues, lookat:=xlWhole)
Debug.Print Fonds1.Address, Fonds2.Address, Fonds3.Address 'Als ik hier "Sluiting.address, VorigeDag.address" aan toevoeg, krijg ik hier al de foutmelding
If blnWeekend Then GoTo Doorgaan
Sheets(4).Select
Range("B3:AA368").Select
With Selection
.Interior.Color = vbWhite
.Font.Bold = False
End With
'AEX
If Sheets(1).[G107] <> "" Then
Sheets(1).[G107].Copy
Else
Sheets(1).[G111].Copy
End If
With Sluiting.Offset(0, intRijAEX) 'Hier krijg ik de foutmelding als ik "Sluiting.address" niet opvraag bij debug.print (regel 46)
.PasteSpecial Paste:=xlPasteValues
.Interior.Color = vbYellow
End With
'Fonds 1
Sheets(1).[H105].Copy
With VorigeDag.Offset(0, intRij1)
.Interior.Color = RGB(191, 149, 223)
End With
With Sluiting.Offset(0, intRij1)
.PasteSpecial Paste:=xlPasteValues
.Interior.Color = vbYellow
End With
'Fonds 2
Sheets(1).[I105].Copy
With VorigeDag.Offset(0, intRij2)
.Interior.Color = RGB(244, 176, 132)
End With
With Sluiting.Offset(0, intRij2)
.PasteSpecial Paste:=xlPasteValues
.Interior.Color = vbYellow
End With
'Fonds 3
Sheets(1).[J105].Copy
With VorigeDag.Offset(0, intRij3)
.Interior.Color = RGB(142, 169, 219)
End With
With Sluiting.Offset(0, intRij3)
.PasteSpecial Paste:=xlPasteValues
.Interior.Color = vbYellow
End With
VorigeDag.Offset(0, intRijAEX).Interior.Color = RGB(255, 192, 0)
Doorgaan:
Sheets(4).[A3:A368].Select
With Selection 'Reset achtergrond datum-kolom
.Interior.Color = RGB(179, 242, 249)
.Font.Bold = False
.Font.Italic = False
.Font.Color = vbBlack
End With
If Time < TimeValue("18:05") Then
With VorigeDag
.Interior.Color = vbYellow
.Font.Bold = True
End With
Else
With Sluiting
.Interior.Color = vbYellow
.Font.Bold = True
End With
End If
Sheets(4).Select
Application.CutCopyMode = False
Sluiting.Select
End Sub
Zie ook mijn commentaar in de Code
Het lijkt wel of "Set Sluiting" en/of "Set VorigeDag" de fout genereert, maar waarom is mij een raadsel.
Code:
Set AEX = Sheets(4).[B2:AA2].Find(What:=strAEX, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds1 = Sheets(4).[B2:AA2].Find(What:=strFonds1, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds2 = Sheets(4).[B2:AA2].Find(What:=strFonds2, LookIn:=xlValues, lookat:=xlWhole)
Set Fonds3 = Sheets(4).[B2:AA2].Find(What:=strFonds3, LookIn:=xlValues, lookat:=xlWhole)
Code:
Set Sluiting = Sheets(4).[A3:A368].Find(What:=dtVandaag, LookIn:=xlValues, lookat:=xlWhole)
Set VorigeDag = Sheets(4).[A3:A368].Find(What:=dtVorigeDag, LookIn:=xlValues, lookat:=xlWhole)
Kan iemand mij uit de droom helpen?