小编Jac*_*son的帖子

在VBA公式中定义和使用名称

好吧,我对VBA很新,我遇到了这个障碍.

我想在VBA中为日期列("日期")定义名称,然后在VBA公式中使用该名称.

这是我在excel中定义名称的地方:

Sub Build_dates(as_of_date As String, curve_source As String)
'Code
Range("B14").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersTo:=Selection.Address
'More Code
End Sub
Run Code Online (Sandbox Code Playgroud)

这是我想用它的子:

Sub Build_times(interp_count As String, as_of_date As String)
    Dim First As Range, Last As Range, fillRange As Range
    Set First = Range("C14")
    Set Last = Range("B14").End(xlDown).Offset(0, 1)
    Set fillRange = Range(First.Address & ":" & Last.Address)
    Select Case interp_count
        Case "Act/360"
            First.Formula = "=(dates-$B$14)/360"
            First.AutoFill Destination:=fillRange
        Case "Act/365"
            First.Formula = "=(dates-$B$14)/365"
            First.AutoFill Destination:=fillRange
    End Select
    'Add name to the time …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1