我在Cell B32中有一个值,我希望能够逐周更改。对于新的一周,我有一个宏,可以将数据复制并粘贴到文件中,但复制/粘贴的位置每周都会更改。
相关代码的一部分在这里:
Dim Week As String
Dim FiscalPeriod As String
Windows("Personal.xls").Activate
Sheets("Store Info").Select
Week = Range("B32").Value
Windows("Budget Load Check.xls").Activate
Sheets("Fcst PT").Select
Rows("4:4").Select
Selection.Find(What:=Week, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
FiscalPeriod = ActiveCell.Address
Selection.Find(What:=Week
如何告诉它在第4行中搜索值,然后找出活动单元格的地址,标签为'FiscalPeriod'。一旦我这样做,我就可以做一系列单元格偏移,将所有内容粘贴到正确的位置。
答案 0 :(得分:0)
我猜你想要找到与数字周完全匹配的内容,并且LookAt:=xlPart
刚刚从之前的搜索中遗留下来。
Dim Week As String, FiscalPeriod As String
Week = Workbooks("Personal.xls").Sheets("Store Info").Range("B32").Value
Windows("Personal.xls").Activate
With ActiveWorkbook.Sheets("Fcst PT")
If Not IsError(Application.Match(Week, .Rows(4), 0)) Then
FiscalPeriod = .Cells(4, Application.Match(Week, .Rows(4), 0)).Address
Else
FiscalPeriod = "not found"
End If
End With