1

vba コードで多くの問題が発生しています。ファイルが開かれたときに実行されるサブを作成しました。ただし、アプリケーション定義またはオブジェクト定義の問題があることを示す実行時エラーが発生し続けます。このコードは、「With Cells(13, dateFinder.Column)」ブロックの下に「With Cells(17, dateFinder.Column)」ブロックがない場合に機能します。

コードは次のとおりです。

Sub equityRaiseOpen()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Worksheets("PRESENTATION")
Set ws2 = Worksheets(7)
ws2.Activate
Dim dateRange As Range
ws2.Unprotect
Dim dte As Date


'this block finds current quarter ending date
If Application.WorksheetFunction.RoundUp(Month(Now()) / 3, 0) = 1 Then
    dte = DateValue("3/31/" & Year(Now()))
ElseIf Application.WorksheetFunction.RoundUp(Month(Now()) / 3, 0) = 2 Then
    dte = DateValue("6/30/" & Year(Now()))
ElseIf Application.WorksheetFunction.RoundUp(Month(Now()) / 3, 0) = 3 Then
    dte = DateValue("9/30/" & Year(Now()))
ElseIf Application.WorksheetFunction.RoundUp(Month(Now()) / 3, 0) = 4 Then
    dte = DateValue("12/31/" & Year(Now()))
End If


Set dateRange = Range("FFO___AFFO_SUMMARY")

Dim iterator As Range
Dim colNum As Integer

'this block finds the column number for the current quarter ending date
For Each iterator In dateRange
    If iterator = dte Then
        colNum = iterator.Column
    End If
Next

ws2.Range("B1") = dte

Dim dateFinder As Range
Set dateFinder = ws2.Range("B1")
Dim i As Integer
'Call putDates
i = 9

'ws2.Unprotect

Dim j As Integer

Set dateFinder = ws2.Range("B1")

For j = 1 To i
    Cells(12, dateFinder.Column) = 0.4
    'create data validiation for debt source
    Debug.Print Cells(13, dateFinder.Column).Address
    With Cells(13, dateFinder.Column)
            .Interior.Color = RGB(255, 255, 255)
            .Locked = False
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            With .Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=DebtList"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
            .Value = "Revolver"
        End With
        With Cells(17, dateFinder.Column)
            .Interior.Color = RGB(255, 255, 255)
            .Locked = False
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            With .Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="ATM,Common, Preferred"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
            .Value = "ATM"
        End With

    Set dateFinder = dateFinder.Offset(0, 2)
Next j



'ws2.Protect
End Sub
4

0 に答える 0