我目前正在编写一些代码,这些代码将用于删除xl工作簿中的一些讨厌的易失性“间接”函数。
我设法编写了尽可能多的代码,但是不幸的是,我变得相当困惑,需要一些帮助才能使我走上正确的道路。
在下面的列表中,我对使用此代码要实现的目标进行了总结。
LOOP
我知道这似乎有点困难。我相信我已经做过很多这样的代码,但是我仍然停留在一些地方,例如在另一个工作簿中选择变量工作表名称!这是我的代码;
Sub TeamData()
Dim i As Range
Dim inputbook As Workbook
Dim C As Range
Dim HomeTeamRange As Range
Dim HomeTeam As Range
Dim HomeTeamValue As Range
Set inputbook = ThisWorkbook
Set TeamPerformance = Workbooks.Open("\\ad.nfumutual.co.uk\Users\Homes1\cs010ea\My Documents\WhoScored Scraping\Betting File\Team Performance Factors.xlsx")
For Each i In Range("A2:A1000")
If i.Value2 = "HT" Then
Set LeagueName = Range("C" & (ActiveCell.Row))
Set HomeTeam = Range("D" & (ActiveCell.Row))
Workbooks("Users\Homes1\cs010ea\My Documents\Team Performance Factors.xlsx").Sheets(LeagueName).Select
Set HomeTeamRange = Range("C:C")
Set HomeTeamValue = HomeTeamRange.Find(what:=HomeTeam, after:=HomeTeamRange(1), searchdirection:=xlPrevious).Offset(0, 8).Copy
ThisWorkbook.Sheets("Input").Range("AO" & (i)).PasteSpecial xlPasteValues
End If
Next
End Sub