Я хотел бы написать некоторый код, который говорит, что если значение ячейки = да, тогда запустите этот код "IF", если нет, то запустите другой код "IF".
Вот мой подпункт:
Sub LTATradesTest()
Application.ScreenUpdating = False
Dim LastRow As Long, fs As Worksheet, ds As Worksheet, x As Long
Dim ltaLR As Long
Dim cmntText As String
With ThisWorkbook
Set fs = .Worksheets("Filters")
Set ds = .Worksheets("Data")
End With
LastRow = ds.Cells.Find("*", LookIn:=xlFormulas, Lookat:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ClearSelections
SortData
RemoveComments
DeleteConditionalFormat
UnmergeAllCells
For x = 4 To LastRow
If fs.Range("F2") = "Yes" Then GoTo Line1 Else GoTo Line2
Line1: If ds.Cells(x, 1) = ds.Range("E1") And ds.Cells(x, 40) >= _
fs.Range("C2") And ds.Cells(x, 41) >= fs.Range("C2") Then Goto Line3
Line2: If ds.Cells(x, 40) >= fs.Range("C2") And ds.Cells(x, 41) >= fs.Range("C2") Then
Line3: With ThisWorkbook.Worksheets("Test")
ltaLR = .Cells.Find("*", LookIn:=xlFormulas, Lookat:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
.Cells(ltaLR, "B").Value = ds.Cells(x, 3) 'League
.Cells(ltaLR, "B").Resize(2, 1).Merge
.Cells(ltaLR, "C").Value = ds.Cells(x, 4) 'Home Team
.Cells(ltaLR + 1, "C").Value = ds.Cells(x, 5) 'Away Team
.Cells(ltaLR, "D").Value = ds.Cells(x, 81) 'Home Pos
.Cells(ltaLR + 1, "D").Value = ds.Cells(x, 91) 'Away Pos
.Cells(ltaLR, "E").Value = ds.Cells(x, 82) 'Home H/A Pos
.Cells(ltaLR + 1, "E").Value = ds.Cells(x, 92) 'Away H/A Pos
.Cells(ltaLR, "F").Value = ds.Cells(x, 83) 'Home H/A FH Pos
.Cells(ltaLR + 1, "F").Value = ds.Cells(x, 93) 'Away H/A FH Pos
.Cells(ltaLR, "G").Value = ds.Cells(x, 84) 'Home H/A SH Pos
.Cells(ltaLR + 1, "G").Value = ds.Cells(x, 94) 'Away H/A SH Pos
.Cells(ltaLR, "H").Value = ds.Cells(x, 85) 'Home Att
.Cells(ltaLR + 1, "H").Value = ds.Cells(x, 95) 'Away Att
.Cells(ltaLR, "I").Value = ds.Cells(x, 86) 'Home Def
.Cells(ltaLR + 1, "I").Value = ds.Cells(x, 96) 'Away Def
.Cells(ltaLR, "J").Value = ds.Cells(x, 88) 'Home H/A Form
.Cells(ltaLR + 1, "J").Value = ds.Cells(x, 98) 'Away H/A Form
'Home Scored
.Cells(ltaLR, "K").Value = Round((ds.Cells(x, 57).Value _
/ ds.Cells(x, 40).Value) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "K")) Then
.Cells(ltaLR, "K").Comment.Delete
End If
.Cells(ltaLR, "K").AddComment Text:=ds.Cells(x, 57).Value & "/" & ds.Cells(x, 40).Value
'Away Scored
.Cells(ltaLR + 1, "K").Value = Round((ds.Cells(x, 71).Value _
/ ds.Cells(x, 41).Value) * 100, 0) & "% (" _
& ds.Cells(x, 71).Value & "/" & ds.Cells(x, 41).Value & ")"
If HasComment(.Cells(ltaLR + 1, "K")) Then
.Cells(ltaLR + 1, "K").Comment.Delete
End If
.Cells(ltaLR + 1, "K").AddComment Text:=ds.Cells(x, 71).Value & "/" & ds.Cells(x, 41).Value
'Home Conceded
.Cells(ltaLR, "L").Value = Round((ds.Cells(x, 58).Value _
/ ds.Cells(x, 40).Value) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "L")) Then
.Cells(ltaLR, "L").Comment.Delete
End If
.Cells(ltaLR, "L").AddComment Text:=ds.Cells(x, 58).Value & "/" & ds.Cells(x, 40).Value & ")"
'Away Conceded
.Cells(ltaLR + 1, "L").Value = Round((ds.Cells(x, 72).Value _
/ ds.Cells(x, 41).Value) * 100, 0) & "%"
If HasComment(.Cells(ltaLR + 1, "L")) Then
.Cells(ltaLR + 1, "L").Comment.Delete
End If
.Cells(ltaLR + 1, "L").AddComment Text:=ds.Cells(x, 72).Value & "/" & ds.Cells(x, 41).Value & ")"
'Combined HT 0-0
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 229).Value _
+ ds.Cells(x, 243).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 229).Value + ds.Cells(x, 243).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined FT 0-0
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 257).Value _
+ ds.Cells(x, 275).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 257).Value + ds.Cells(x, 275).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined O1.5
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 54).Value + _
ds.Cells(x, 68).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 54).Value + ds.Cells(x, 68).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined O2.5
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 55).Value _
+ ds.Cells(x, 69).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 55).Value + ds.Cells(x, 69).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined O3.5
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 56).Value _
+ ds.Cells(x, 70).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 56).Value + ds.Cells(x, 70).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined BTS
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 59).Value _
+ ds.Cells(x, 73).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 59).Value + ds.Cells(x, 73).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined GP 1-0
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 144).Value _
+ ds.Cells(x, 159).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 144).Value + ds.Cells(x, 159).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
'Combined GP 0-1
.Cells(ltaLR, "M").Value = Round(((ds.Cells(x, 147).Value _
+ ds.Cells(x, 162).Value) / (ds.Cells(x, 40).Value _
+ ds.Cells(x, 41).Value)) * 100, 0) & "%"
If HasComment(.Cells(ltaLR, "M")) Then
.Cells(ltaLR, "M").Comment.Delete
End If
.Cells(ltaLR, "M").AddComment Text:=(ds.Cells(x, 147).Value + ds.Cells(x, 162).Value) & "/" _
& (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
.Cells(ltaLR, "M").Resize(2, 1).Merge
End With
End If
Next x
Application.ScreenUpdating = True
End Sub
Единственная разница между двумя операторами IF, из которых я хочу выбрать, заключается в следующей строке кода:
If ds.Cells(x, 1) = ds.Range("E1")
Я пытался использовать IF GOTO THEN ELSE, но это не работает.Кто-нибудь может указать, где я иду не так?