I would like some help with a problem, which I imagine requires some VBA. I would like to transfer data from one table to another, based on a cell value that you can define.
Please refer to the image above for the description of the problem.
I would like to be able to 'store' the score data from each corresponding Team from the table on the right, to the table on the left depending on the week selected.
Eg Team 2 has a score of 10 in Week 1, therefore, when I click the STORE button, I would like to store it in its corresponding spot on the table on the left. However for all teams.
If I understood your question correctly then the following code will loop through the TeamIDs and Scores and place them in the correct Week Number on the other table:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.