根据日期选择动态范围并粘贴范围内的公式

时间:2019-02-11 09:50:00

标签: excel vba

我想在基于日期的范围内粘贴一个公式。日期是从L7列到AP7 1st到31st。公式应在日期下方选择一个动态范围,然后粘贴公式。

我做了一个宏,它只选择了在宏上选择的范围

s_date = Sheets("PnA").Range("L1") 
Range("L5").Select 
Selection.Copy 
Range("L7:AP7").Select 
Selection.Find(What:=s_date, After:=ActiveCell, LookIn:=xlFormulas _ , 
     LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
     MatchCase:=False, SearchFormat:=False).Activate 
ActiveCell.Select 
Selection.Offset(1, 0).Select 
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ 
    SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False"
Selection.AutoFill Destination:=Range("L8:L673")
Range("L8:L673").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False" 

1 个答案:

答案 0 :(得分:0)

这是我可以利用您提供的有限信息获得的信息,现在还不清楚您要完成什么

Sub finddate ()
With Workbooks(REFERENCE).Sheets(REFERENCE) 'Change

s_date = .Range("L1") 
Set fdate = .Range("L7:AP7").Find(s_date, LookIn:=xlFormulas, LookAt:=xlPart)

If Not fdate is Nothing Then
    fdate.Offset(0,1).AutoFill Destination:=.Range(fdate.Offset(0,1) & ":" & fdate.Offset(1,673))'I am assuming there is a formula to the right of the date which you want autofilled down
End If

End With
End Sub