[英]Transfer Data from One Table to Another Based on Cell Values
如果我正確理解了您的問題,那么以下代碼將循環遍歷 TeamID 和分數,並將它們放在另一個表上的正確周數中:
Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set your worksheet, amend as required
Dim FoundID As Range, FoundID2 As Range
Dim TeamID As String, TeamID2 As String
Dim Score As String, Score2 As String
WeekNumber = ws.Range("M3").Value
'get WeekNumber to use for Offset
For i = 5 To 13
TeamID = ws.Cells(i, 13)
Score = ws.Cells(i, 15)
TeamID2 = ws.Cells(i, 18)
Score2 = ws.Cells(i, 16)
Set FoundID = ws.Range("B3:B21").Find(What:=TeamID)
If Not FoundID Is Nothing Then
FoundID.Offset(0, WeekNumber).Value = Score
End If
Set FoundID2 = ws.Range("B3:B21").Find(What:=TeamID2)
If Not FoundID2 Is Nothing Then
FoundID2.Offset(0, WeekNumber).Value = Score2
End If
Next i
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.